% The results should be compared to the PRCC results section in % Supplementary Material D and Table D.1 for different N (specified by % "runs" in the script below clear all; close all; rng(2); % Sample size N runs=100; % LHS MATRIX Parameter_settings_LHS; % LHS_Call(xmin,xmean,xmax,xsd,nsample,distrib,threshold) r_LHS = LHS_Call(5, R, 20, 0 ,runs,'unif'); rcw_LHS = LHS_Call(0.5, Nc, 2, 0 ,runs,'unif'); rdw_LHS = LHS_Call(4, Nd, 15, 0 ,runs,'unif'); m_LHS = LHS_Call(5, m, 20, 0 ,runs,'unif'); bc2_LHS = LHS_Call(7, bc2, 18, 0 ,runs,'unif'); bw2_LHS = LHS_Call(2, bw2, 18, 0 ,runs,'unif'); % LHS MATRIX and PARAMETER LABELS LHSmatrix=[r_LHS rcw_LHS rdw_LHS m_LHS bc2_LHS bw2_LHS]; Tc_lhs = zeros(1,runs); for x=1:runs %Run solution x times choosing different values x % maximize profit for range of tip rates [pmax1,~,~] = max_profit2(t0,tend,LHSmatrix(x,4),LHSmatrix(x,4),tip_conventional,tip_conventional,... LHSmatrix(x,1),LHSmatrix(x,5),LHSmatrix(x,6),min_bw,min_bc,LHSmatrix(x,3),1,LHSmatrix(x,2),IC,[min_bw,min_bc]); % maximize profit for no tipping allowed (T2 is increasing vector of conventional tip rates) [pmax2,~,~] = max_profit2(t0,tend,LHSmatrix(x,4),LHSmatrix(x,4),zeros(1,length(tip_conventional)),tip_conventional,... LHSmatrix(x,1),LHSmatrix(x,5),LHSmatrix(x,6),min_bw,min_bc,LHSmatrix(x,3),1,LHSmatrix(x,2),IC,[min_bw,min_bc]); % 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 % save Tc value for PRCC analysis Tc_lhs(1,x) = Tc; figure plot(tip_conventional,pmax1,'o-k') hold on plot(tip_conventional,pmax2,'o-r') xlabel('conventional tip rate','FontSize',14) ylabel('restaurant profitibility (unitless)','FontSize',14) legend('allow tipping','forbid tipping') end % Save the workspace save Model_LHS.mat; %CALCULATE PRCC alpha=0.01; [prccT, signT, sign_labelT]=PRCC(LHSmatrix,Tc_lhs,1,PRCC_var,alpha); %PRCC_PLOT(LHSmatrix,V_T,1:length(time_points),PRCC_var,y_var_label)