% optimize restaurant strategy at equilibrium % hold menu price, R, total people constant % hold competition parameters constant % select tip rate T1, and base pays bw1, bc1 (within legal limits) to maximize profit function Tc = compute_Tc(m1,m2,T1,T2,R,bw1,bw2,bc1,bc2,min_bw,min_bc,Nd,Nw,Nc,t0,tend,IC) tip_conventional = 0:0.05:0.5; tip_conventional = [0,0.01,0.02,0.03,0.04,0.05,0.1,0.15,0.2,0.25,0.3,0.4,0.5]; % maximize profit for range of tip rates [pmax1,~,~] = max_profit2(t0,tend,m1,m2,tip_conventional,tip_conventional,R,bw2,bc2,min_bw,min_bc,Nd,Nw,Nc,IC,[bw1,bc1]); % maximize profit for no tipping allowed (T2 is increasing vector of conventional tip rates) [pmax2,~,~] = max_profit2(t0,tend,m1,m2,zeros(1,length(tip_conventional)),tip_conventional,R,bw2,bc2,min_bw,min_bc,Nd,Nw,Nc,IC,[bw1,bc1]); % residuals between strategies res = pmax1-pmax2; res_sign = res(1:length(res)-1).*res(2:end); % index before strategy switch ind = find(res_sign<=0); % check if Tc = 0 is not only switch if ind(end)>1 % index of first switch after Tc = 0 (all numerical exploration indicates there are at most 2) ii = ind(2); % (x1,y1) and (x2,y2) are line segment for pmax1 x1 = tip_conventional(ii); y1 = pmax1(ii); x2 = tip_conventional(ii+1); y2 = pmax1(ii+1); % (x3,y3) and (x4,y4) are line segment for pmax2 x3 = x1; y3 = pmax2(ii); x4 = x2; y4 = pmax2(ii+1); % find x value of intersection (https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line) Tc = ((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)); else Tc = 0; end % figure % plot(tip_conventional,pmax1,'o-k') % hold on % plot(tip_conventional,pmax2,'o-r') % line([Tc Tc], [min([pmax1; pmax2]) max([pmax1; pmax2])]); % xlabel('conventional tip rate','FontSize',14) % ylabel('restaurant profitibility (unitless)','FontSize',14) % legend('allow tipping','forbid tipping') end