
Department of Engineering 


Next: Algebra
Up: Maths
Previous: Numerical Analysis
If you know that your matrices will stay nearly empty, then make
them sparse  they'll take up less space and can be operated on
more quickly.
% comparison of sparse vs full matrices
% Create sparse and full versions of the same matrix.
% Note that the density is 0.05. The breakeven point
% for this operation seems to be about 0.25.
S = sprandn(60,60,0.05);
F = full(S);
% Compare speed.
disp('Sparse')
t0=cputime;
B = S * S;
cputimet0
disp('Full')
t0=cputime;
C = F * F;
cputimet0