-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2casesUub.m
113 lines (101 loc) · 3.62 KB
/
plot2casesUub.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
% M-file for Plotting Two Cases of Initial State Perturbation for Uniform Upper Bound
%
% Toshiyuki Ohtsuka, March - May 2024
clear;
load("Perturbed/RHOT/dvarsettings.mat"); % MAT file of settings
figname = "comp2cases_RHOT_Uub0p9"; % Figure name
optname1 = "Uub0p9L2"; % Name of optimization problem for Case 1
optname2 = "Uub0p9L1"; % Name of optimization problem for Case 2
figdir = dirvar; % Directory to save figure
optdir1 = dirvar+filesep+optname1; % Directory of Case 1
load(optdir1+filesep+"dvarans.mat"); % Data of Case 1
dvaransmat1 = dvaransmat; % Initial state perturbation in Case 1
totalPREC11 = totalPREC1; % Total PREC after perturbation in Case 1
optdir2 = dirvar+filesep+optname2; % Directory of Case 2
load(optdir2+filesep+"dvarans.mat"); % Data of Case 2
dvaransmat2 = dvaransmat; % Initial state perturbation in Case 2
totalPREC12 = totalPREC1; % Total PREC after perturbation in Case 2
% totalPREC_org and totalPRECref must be same for all data.
%%%% Prepare Labels for Figures %%%%
x1 = "Grid y";
y1 = "Grid z";
if varname == "RHOT"
z1 = "\Delta \rho \theta [kg \cdot K/m^3]"; % z label
end
if varname == "QV"
z1 = "\Delta q_v"; % z label
end
t1 = "(a) Minimum $\ell_2$ Norm Solution"; % title
x2 = x1;
y2 = y1;
z2 = z1;
t2 = "(b) Minimum $\ell_1$ Norm Solution";
x3 = "Position y [m]";
y3 = "Accumulated Precipitation [mm]";
t3 = "(c) Accumulated Precipitation"; % title
% legend
if varname == "RHOT"
leg3 = ["Nominal", "$\rho \theta$ Perturbed (Min $\ell_2$ Norm)", "$\rho \theta$ Perturbed (Min $\ell_1$ Norm)", "Upper Bound"];
end
if varname == "QV"
leg3 = ["Nominal", "$q_v$ Perturbed (Min $\ell_2$ Norm)", "$q_v$ Perturbed (Min $\ell_1$ Norm)", "Upper Bound"];
end
x4 = x3;
y4 = "Accumulated Precipitation "+newline+"over Upper Bound [mm]";
t4 = "(d) Upper Bound Violation"; % title
% legend
if varname == "RHOT"
leg4 = ["$\rho \theta$ Perturbed (Min $\ell_2$ Norm)", "$\rho \theta$ Perturbed (Min $\ell_1$ Norm)"];
end
if varname == "QV"
leg4 = ["$q_v$ Perturbed (Min $\ell_2$ Norm)", "$q_v$ Perturbed (Min $\ell_1$ Norm)"];
end
FP = [100,100,1000,700]; % Figure Position
FS = 11; % Font Size
%%%% Plot Perturbations of Initial Condition %%%%
f = figure;
f.Position = FP;
subplot(2,2,1);
surf(dvaransmat1');
set(gca,'FontSize',FS);
xlabel(x1);
ylabel(y1);
zlabel(z1);
title(t1,'Interpreter','latex');
subplot(2,2,2);
surf(dvaransmat2');
set(gca,'FontSize',FS);
xlabel(x2);
ylabel(y2);
zlabel(z2);
title(t2,'Interpreter','latex');
%%%% Plot Accumulated Precipitations %%%%
subplot(2,2,3);
plot(datay,totalPREC_org,'k-','LineWidth',1);
hold on;
plot(datay,totalPREC11,'g-',datay,totalPREC12,'b-','LineWidth',2);
plot(datay,totalPRECref,'r--','LineWidth',1);
legend(leg3,'Location','northwest','Interpreter','latex');
set(gca,'FontSize',FS);
xlabel(x3);
ylabel(y3);
title(t3,'Interpreter','latex');
hold off;
%%%% Plot Upper Bound Violation %%%%
%totalPRECerr1 = max(totalPREC11 - totalPRECref,zeros(size(totalPRECref)));
%totalPRECerr2 = max(totalPREC12 - totalPRECref,zeros(size(totalPRECref)));
totalPRECerr1 = max(totalPREC11 - totalPRECref,0);
totalPRECerr2 = max(totalPREC12 - totalPRECref,0);
subplot(2,2,4);
plot(datay,totalPRECerr1,'g-',datay,totalPRECerr2,'b-','LineWidth',2);
ylim([0 inf]);
legend(leg4,'Location','northwest','Interpreter','latex');
set(gca,'FontSize',FS);
xlabel(x4);
ylabel(y4);
title(t4,'Interpreter','latex');
hold off;
%%%% Save Figures %%%%
savefig(figdir+filesep+figname);
exportgraphics(f,figdir+filesep+figname+'.pdf','ContentType','vector');
exportgraphics(f,figdir+filesep+figname+'.png');