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
| clc
clear all
Nmax = 1000;
k = 1;
for N = 100:100:Nmax
A = randi(1000,N); B = randi(1000,N); C = randi(1000,N);
D = randi(1000,N,1);
tic
for i = 1:20
M1 = A*B*C*D;
end
t1(k) = toc;
tic
for i = 1:20
M2 = A*(B*(C*D));
end
t2(k) = toc;
err(k) = max(abs(M1(:)-M2(:)));
k = k+1;
end
whos
N = 100:100:Nmax;
figure
% [ax,h1,h2]= plotyy([N;N].',[t1;t2].',N,err,'semilogy','plot');
[ax,h1,h2]= plotyy([N;N].',[t1;t2].',N,err,'plot','plot');
set([h1;h2],'linewidth',2)
ylabel(ax(1),'t (s)');
ylabel(ax(2), 'err');
xlabel(ax(1), 'N');
legend([h1;h2],{'t1' 't2' 'err (max)'},'Location','NorthWest') |
Partager