Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Algebra Up: Maths Previous: Numerical Analysis

Sparse Matrices

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 break-even 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;
cputime-t0
disp('Full')
t0=cputime;
C = F * F;
cputime-t0



© Cambridge University Engineering Dept
Information provided by Tim Love
2006-07-24