
clc;  clear;  close
load ("data/Parameters.mat",'m');

JJ = 41;
dis = 0.025;

%% The equilibrium
% Case 1: competition + prohibit
tic
m.DataPolicy = 'prohibit';  % prohibit free
m.MarketStruct = 'competition';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

for i = 1:JJ
    m.t_cu = 0 + dis*(i-1);
    m.tau_cu = m.d_cu*(1+m.t_cu);
    m.t_uc = 0;

    [wel1,Case11] = func_eqm_iter(m);
    Case1.t_cu(i,1) = m.t_cu;
    Case1.wel_c(i,1) = Case11.wel_c;
    Case1.wel_u(i,1) = Case11.wel_u;
    Case1.w_c(i,1) = Case11.w_c;
    Case1.w_u(i,1) = Case11.w_u;
    Case1.Pi_c(i,1) = Case11.Pi_c;
    Case1.Pi_u(i,1) = Case11.Pi_u;
    Case1.M_c(i,1) = Case11.M_c;
    Case1.M_u(i,1) = Case11.M_u;
    Case1.tariff_c(i,1) = Case11.tariff_c;
    Case1.tariff_u(i,1) = Case11.tariff_u;
    Case1.P_c(i,1) = Case11.P_c;
    Case1.P_u(i,1) = Case11.P_u;
    Case1.Data_c(i,1) = Case11.Data_c;
    Case1.Data_u(i,1) = Case11.Data_u;
    Case1.Upsilon_c(i,1) = Case11.Upsilon_c;
    Case1.Upsilon_u(i,1) = Case11.Upsilon_u;
end

ub = [];   lb = 0;   opt0 = 0;
[opt_Case1, fval, exitflag] =  knitromatlab(@(opt)func_obj_t_cu(opt,m), opt0, [], [], [], [], lb, ub, [], [], [], 'ktropt_singlestart.opt');
Case1.t_cu_opt = opt_Case1;         % optimal tariff and welfare
m.t_cu = opt_Case1;
m.tau_cu = m.d_cu*(1+m.t_cu);
[wel1,Case11] = func_eqm_iter(m);
Case1.wel_c_opt = Case11.wel_c;
Case1.wel_u_opt = Case11.wel_u;


% Case 2: competition + free
m.DataPolicy = 'free';  % prohibit free
m.MarketStruct = 'competition';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

for i = 1:JJ
    m.t_cu = 0 + dis*(i-1);
    m.tau_cu = m.d_cu*(1+m.t_cu);
    m.t_uc = 0;

    [wel2,Case22] = func_eqm_iter(m);
    Case2.t_cu(i,1) = m.t_cu;
    Case2.wel_c(i,1) = Case22.wel_c;
    Case2.wel_u(i,1) = Case22.wel_u;
    Case2.w_c(i,1) = Case22.w_c;
    Case2.w_u(i,1) = Case22.w_u;
    Case2.Pi_c(i,1) = Case22.Pi_c;
    Case2.Pi_u(i,1) = Case22.Pi_u;
    Case2.M_c(i,1) = Case22.M_c;
    Case2.M_u(i,1) = Case22.M_u;
    Case2.tariff_c(i,1) = Case22.tariff_c;
    Case2.tariff_u(i,1) = Case22.tariff_u;
    Case2.P_c(i,1) = Case22.P_c;
    Case2.P_u(i,1) = Case22.P_u;
    Case2.Data_c(i,1) = Case22.Data_c;
    Case2.Data_u(i,1) = Case22.Data_u;
    Case2.Upsilon_c(i,1) = Case22.Upsilon_c;
    Case2.Upsilon_u(i,1) = Case22.Upsilon_u;
end

ub = [];   lb = 0;   opt0 = 0;
[opt_Case2, fval, exitflag] =  knitromatlab(@(opt)func_obj_t_cu(opt,m), opt0, [], [], [], [], lb, ub, [], [], [], 'ktropt_singlestart.opt');
Case2.t_cu_opt = opt_Case2;         % optimal tariff and welfare
m.t_cu = opt_Case2;
m.tau_cu = m.d_cu*(1+m.t_cu);
[wel2,Case22] = func_eqm_iter(m);
Case2.wel_c_opt = Case22.wel_c;
Case2.wel_u_opt = Case22.wel_u;


% Case 3: monopoly + prohibit
m.DataPolicy = 'prohibit';  % prohibit free
m.MarketStruct = 'monopoly';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

for i = 1:JJ
    m.t_cu = 0 + dis*(i-1);
    m.tau_cu = m.d_cu*(1+m.t_cu);
    m.t_uc = 0;

    [wel3,Case33] = func_eqm_iter(m);
    Case3.t_cu(i,1) = m.t_cu;
    Case3.wel_c(i,1) = Case33.wel_c;
    Case3.wel_u(i,1) = Case33.wel_u;
    Case3.w_c(i,1) = Case33.w_c;
    Case3.w_u(i,1) = Case33.w_u;
    Case3.Pi_c(i,1) = Case33.Pi_c;
    Case3.Pi_u(i,1) = Case33.Pi_u;
    Case3.M_c(i,1) = Case33.M_c;
    Case3.M_u(i,1) = Case33.M_u;
    Case3.tariff_c(i,1) = Case33.tariff_c;
    Case3.tariff_u(i,1) = Case33.tariff_u;
    Case3.P_c(i,1) = Case33.P_c;
    Case3.P_u(i,1) = Case33.P_u;
    Case3.Data_c(i,1) = Case33.Data_c;
    Case3.Data_u(i,1) = Case33.Data_u;
    Case3.Upsilon_c(i,1) = Case33.Upsilon_c;
    Case3.Upsilon_u(i,1) = Case33.Upsilon_u;
end

ub = [];   lb = 0;   opt0 = 0;
[opt_Case3, fval, exitflag] =  knitromatlab(@(opt)func_obj_t_cu(opt,m), opt0, [], [], [], [], lb, ub, [], [], [], 'ktropt_singlestart.opt');
Case3.t_cu_opt = opt_Case3;         % optimal tariff and welfare
m.t_cu = opt_Case3;
m.tau_cu = m.d_cu*(1+m.t_cu);
[wel3,Case33] = func_eqm_iter(m);
Case3.wel_c_opt = Case33.wel_c;
Case3.wel_u_opt = Case33.wel_u;


% Case 4: monopoly + free
m.DataPolicy = 'free';  % prohibit free
m.MarketStruct = 'monopoly';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

for i = 1:JJ
    m.t_cu = 0 + dis*(i-1);
    m.tau_cu = m.d_cu*(1+m.t_cu);
    m.t_uc = 0;

    [wel4,Case44] = func_eqm_iter(m);
    Case4.t_cu(i,1) = m.t_cu;
    Case4.wel_c(i,1) = Case44.wel_c;
    Case4.wel_u(i,1) = Case44.wel_u;
    Case4.w_c(i,1) = Case44.w_c;
    Case4.w_u(i,1) = Case44.w_u;
    Case4.Pi_c(i,1) = Case44.Pi_c;
    Case4.Pi_u(i,1) = Case44.Pi_u;
    Case4.M_c(i,1) = Case44.M_c;
    Case4.M_u(i,1) = Case44.M_u;
    Case4.tariff_c(i,1) = Case44.tariff_c;
    Case4.tariff_u(i,1) = Case44.tariff_u;
    Case4.P_c(i,1) = Case44.P_c;
    Case4.P_u(i,1) = Case44.P_u;
    Case4.Data_c(i,1) = Case44.Data_c;
    Case4.Data_u(i,1) = Case44.Data_u;
    Case4.Upsilon_c(i,1) = Case44.Upsilon_c;
    Case4.Upsilon_u(i,1) = Case44.Upsilon_u;
end

ub = [];   lb = 0;   opt0 = 0;
[opt_Case4, fval, exitflag] =  knitromatlab(@(opt)func_obj_t_cu(opt,m), opt0, [], [], [], [], lb, ub, [], [], [], 'ktropt_singlestart.opt');
Case4.t_cu_opt = opt_Case4;         % optimal tariff and welfare
m.t_cu = opt_Case4;
m.tau_cu = m.d_cu*(1+m.t_cu);
[wel4,Case44] = func_eqm_iter(m);
Case4.wel_c_opt = Case44.wel_c;
Case4.wel_u_opt = Case44.wel_u;
toc

%% Figure：贸易政策和福利
warning('off','all')

set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture1 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.wel_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.wel_u, 6, '^', 'k');
hold off;
xl = xline(Case1.t_cu_opt,':k');
xl.LineWidth = 1.2;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('福利','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.wel_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.wel_u, 6, '^', 'k');
hold off;
xl = xline(Case2.t_cu_opt,':k');
xl.LineWidth = 1.2;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('福利','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.wel_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.wel_u, 6, '^', 'k');
hold off;
xl = xline(Case3.t_cu_opt,':k');
xl.LineWidth = 1.2;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('福利','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.wel_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.wel_u, 6, '^', 'k');
hold off;
xl = xline(Case4.t_cu_opt,':k');
xl.LineWidth = 1.2;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('福利','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U','最优关税'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)

fprintf('\n=================================================================\n');
fprintf('         图3  国家𝐶征收单边进口关税时两国的福利变化（左）\n');
fprintf('=================================================================\n\n');
print(picture1,'result/图3（左）.png','-r600','-djpeg');


%% Figure：贸易政策和商品贸易赤字
set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture2 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.Upsilon_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.Upsilon_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品贸易赤字','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.Upsilon_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.Upsilon_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品贸易赤字','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.Upsilon_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.Upsilon_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品贸易赤字','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.Upsilon_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.Upsilon_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品贸易赤字','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)

fprintf('\n=================================================================\n');
fprintf('         图3  国家𝐶征收单边进口关税时两国的商品贸易赤字变化（右）\n');
fprintf('=================================================================\n\n');
print(picture2,'result/图3（右）.png','-r600','-djpeg');

%% Figure：贸易政策和工资
set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture3 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.w_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.w_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('工资','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.w_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.w_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('工资','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.w_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.w_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('工资','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.w_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.w_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('工资','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)

fprintf('\n=================================================================\n');
fprintf('         图I6 国家𝐶征收单边进口关税时两国的工资水平\n');
fprintf('=================================================================\n\n');
print(picture3,'result/图I6.png','-r600','-djpeg');


%% Figure：商品生产者利润
set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture4 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.Pi_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.Pi_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品生产者利润','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.Pi_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.Pi_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品生产者利润','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.Pi_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.Pi_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品生产者利润','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.Pi_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.Pi_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('商品生产者利润','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)


fprintf('\n=================================================================\n');
fprintf('         图I7 国家𝐶征收单边进口关税时两国的商品生产者利润\n');
fprintf('=================================================================\n\n');
print(picture4,'result/图I7.png','-r600','-djpeg');


%% Figure：数据中间商利润
set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture5 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.M_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.M_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('数据中间商利润','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.M_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.M_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('数据中间商利润','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.M_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.M_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('数据中间商利润','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.M_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.M_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('数据中间商利润','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)


fprintf('\n=================================================================\n');
fprintf('         图I8 国家𝐶征收单边进口关税时两国的数据中间商利润\n');
fprintf('=================================================================\n\n');
print(picture5,'result/图I8.png','-r600','-djpeg');



%% Figure：关税收入
set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture6 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.tariff_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.tariff_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('关税收入','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.tariff_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.tariff_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('关税收入','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.tariff_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.tariff_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('关税收入','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.tariff_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.tariff_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('关税收入','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)

fprintf('\n=================================================================\n');
fprintf('         图I9 国家𝐶征收单边进口关税时两国的关税收入\n');
fprintf('=================================================================\n\n');
print(picture6,'result/图I9.png','-r600','-djpeg');



%% Figure：价格指数
set(0, 'defaulttextinterpreter','latex')
set(0, 'defaultAxesTickLabelInterpreter','latex'); 
set(0, 'defaultLegendInterpreter','latex');
set(groot,'defaultLineLineWidth',2); 

TightPlot.ColumeNumber = 2; 
TightPlot.RowNumber = 2;
TightPlot.GapW = 0.1;
TightPlot.GapH = 0.15;
TightPlot.MarginsLower = 0.15;
TightPlot.MarginsUpper = 0.1;
TightPlot.MarginsLeft = 0.1;
TightPlot.MarginsRight = 0.1;

picture7 = figure('color',[1 1 1]);
p = tight_subplot(TightPlot.ColumeNumber,TightPlot.RowNumber,...
    [TightPlot.GapH TightPlot.GapW],...
    [TightPlot.MarginsLower TightPlot.MarginsUpper],...
    [TightPlot.MarginsLeft TightPlot.MarginsRight]); 

axes(p(1));
line(Case1.t_cu,Case1.P_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case1.t_cu, Case1.P_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('价格指数','interpreter','latex', 'FontSize',10);
title(p(1),'（a）竞争/禁止流动','FontSize',10)

axes(p(2));
line(Case2.t_cu,Case2.P_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case2.t_cu, Case2.P_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('价格指数','interpreter','latex', 'FontSize',10);
title(p(2),'（b）竞争/自由流动','FontSize',10)

axes(p(3));
line(Case3.t_cu,Case3.P_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case3.t_cu, Case3.P_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('价格指数','interpreter','latex', 'FontSize',10);
title(p(3),'（c）垄断/禁止流动','FontSize',10)

axes(p(4));
line(Case4.t_cu,Case4.P_c, 'Color', 'k', 'LineStyle', '-', 'LineWidth', 1.25);
hold on;
scatter(Case4.t_cu, Case4.P_u, 6, '^', 'k');
hold off;
set(gca, 'XTickLabelMode', 'auto');
set(gca,'yTickLabel',num2str(get(gca,'yTick')','%.2f'));
xlabel('$ t_{CU} $','Interpreter','latex', 'FontSize',10);
ylabel('价格指数','interpreter','latex', 'FontSize',10);
title(p(4),'（d）垄断/自由流动','FontSize',10)

handle = legend({'国家 C', '国家 U'});
set(handle,'Position', [0.45 0.0000001 0.1 0.05],'Orientation','horizon','Interpreter','latex','FontSize',8)


fprintf('\n=================================================================\n');
fprintf('         图I10 国家𝐶征收单边进口关税时两国的价格指数\n');
fprintf('=================================================================\n\n');
print(picture7,'result/图I10.png','-r600','-djpeg');





