-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_expm3.m
154 lines (129 loc) · 4.04 KB
/
test_expm3.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
% The code tests the 3rd example in section 6 and generates Figure 6.3.
%
% IMFORMATION - This test took about 5 mins on a laptop equipped with an
% Intel i7-6700HQ processor running at 2.60GHz and with 16GB of RAM.
format compact
addpath('data');
addpath('external');
addpath('include');
warning('off');
% reproduce the results?
produce_results = false;
% save the plots?
save_results = true;
% initialization
% marker styles
marker_nd = '^';
marker_mlm = 'o';
% colours
color_nd = [0.8500, 0.3250, 0.0980];
color_mlm = [0, 0.4470, 0.9410];
% color_cond = [0.2, 0.8450, 0.9330];
color_cond = [0, 0, 0];
% line styles
ls_cond = '-';
% linewidth
lw = 1.3;
lwcond = 1.5;
lw_ca = 1.3;
msize = 10; % marker size
ca_fsize = 14;
title_fsize = 18;
lgd_fsize = 14;
ymin = 1e-18;
ymax = 1e0;
xmin = 0;
xmax = 33;
% xticks_str = [0 4 8 12 16 20 24 28 32];
yticks_str = [1e-17 1e-13 1e-9 1e-5 1e0];
lcn = 'NorthEast';
yaxis_label = 'Normwise relative errors';
% generate the test matrix A_{21}
rng(1);
num_mat = mlm_testmats_mct(0);
n = 10;
u = eps(1/2);
alpha = 0.8;
beta = [1.2 8.0];
num_beta = length(beta);
% initialization the arrays for storing the errors and conds
error_nd = zeros(num_mat,num_beta);
error_mlm = zeros(num_mat,num_beta);
condu = zeros(num_mat,num_beta);
if produce_results
main_loop = tic; % record the time consumption
for k = 1:num_mat
for j = 1:num_beta
A = mlm_testmats_mct(k,n);
[error_nd(k,j),error_mlm(k,j)] = mlm_comput_error(A,alpha,beta(j));
condfunc = @(A) mlm_mlm(A,alpha,beta(j));
condu(k,j) = funm_condest1(A, condfunc)*u;
end
fprintf('Testing the %.2dth matrix...\n', k);
end
for j=1:num_beta % stores condition numbers
[condu(:,j),order] = sort(condu(:,j),'descend');
error_nd(:,j)= error_nd((order),j);
error_mlm(:,j)= error_mlm((order),j);
end
fprintf('The test took %.2f minutes.\n', toc(main_loop)/60);
save('data/exmp3.mat','num_mat','error_nd','error_mlm','condu');
else
load('data/exmp3.mat');
end
% map any error less than 1e-17 to 1e-17
miny = 1e-17;
for j=1:num_beta
error_nd((error_nd(:,j)<miny),j) = miny;
error_mlm((error_mlm(:,j)<miny),j) = miny;
end
% figure for beta = 1.2
figure
clf;
hold on
plot(1:num_mat,error_mlm(:,1),marker_mlm,'MarkerSize',msize,'LineWidth',lw,'color',color_mlm);
plot(1:num_mat,error_nd(:,1),marker_nd,'MarkerSize',msize,'LineWidth',lw,'color',color_nd);
plot(1:num_mat,condu(:,1),ls_cond,'LineWidth',lwcond,'color',color_cond);
hold off
set(gca,'linewidth',lw_ca)
set(gca,'fontsize',ca_fsize)
set(gca, 'YScale', 'log')
lgd = legend('mlm', 'funm\_nd', 'Location', lcn);
lgd.FontSize = lgd_fsize;
box on
xlim([xmin,xmax]);
ylim([ymin,ymax]);
% xticks(xticks_str);
yticks(yticks_str);
% ylabel(yaxis_label,'interpreter','latex','FontWeight','normal','fontsize',title_fsize)
title('$\alpha=0.8$, $\beta=1.2$','interpreter','latex','FontWeight','normal','fontsize',title_fsize)
if save_results
set(gcf, 'Color', 'w')
str = ('../figs/exmp3_beta12.pdf');
export_fig(str)
end
% figure for beta = 8.0
figure
clf;
hold on
plot(1:num_mat,error_mlm(:,2),marker_mlm,'MarkerSize',msize,'LineWidth',lw,'color',color_mlm);
plot(1:num_mat,error_nd(:,2),marker_nd,'MarkerSize',msize,'LineWidth',lw,'color',color_nd);
plot(1:num_mat,condu(:,2),ls_cond,'LineWidth',lwcond,'color',color_cond);
hold off
set(gca,'linewidth',lw_ca)
set(gca,'fontsize',ca_fsize)
set(gca, 'YScale', 'log')
lgd = legend('mlm', 'funm\_nd', 'Location', lcn);
lgd.FontSize = lgd_fsize;
box on
xlim([xmin,xmax]);
ylim([ymin,ymax]);
% xticks(xticks_str);
yticks(yticks_str);
% ylabel(yaxis_label,'interpreter','latex','FontWeight','normal','fontsize',title_fsize)
title('$\alpha=0.8$, $\beta=8.0$','interpreter','latex','FontWeight','normal','fontsize',title_fsize)
if save_results
set(gcf, 'Color', 'w')
str = ('../figs/exmp3_beta80.pdf');
export_fig(str)
end