Maybe this is not, what you want:
for n = 500:50:1000
tic
t1(n) = toc;
end
Setting t(500) in the 1st step ist not useful. Better:
nList = 500:50:1000
for k = 1:numel(nList)
n = nList(k);
tic
...
t1(k) = toc;
end
Or the full code without the time wasting "brute clearing header":
function YourFcn
nList = 500:50:1000;
for k = 1:numel(nList)
n = nList(k);
e = ones(n,1);
A = spdiags([-2*e 0*e 6*e 0*e -2*e],-2:2,n,n);
b = -(2:n+1).' .^ 2;
tic;
L1 = chol(A,'lower');
y1 = L1 \ b;
x1 = L1' \ y1;
t1(k) = toc;
A2 = full(A);
tic;
L2 = chol(A2,'lower');
y2 = L2 \ b;
x2 = L2' \ y2;
t2(k) = toc;
end
plot(nList, t1, 'ro', 'markerfacecolor', 'r')
hold on
plot(nList, t2, 'bo', 'markerfacecolor', 'b')
axis tight
end
1 Comment
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/718405-how-to-code-sparse-diagonal-matrix-of-increasing-dimensions#comment_1267230
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/718405-how-to-code-sparse-diagonal-matrix-of-increasing-dimensions#comment_1267230
Sign in to comment.