next up previous contents
Next: Calculus Up: Further MATLAB Previous: Text

Sparse Matrices

MATLAB has two matrix storage modes. Full storage is the default and stores the value of each element; it is appropriate for matrices with many nonzero elements. Sparse storage is used only when you explicitly invoke it (though it propagates somewhat thereafter); it stores only the values of the nonzero elements (and their integer indices, of course). It is therefore appropriate for matrices with few nonzero elements, i.e. sparse matrices.

The advantages of sparse matrices are size and speed. A 5000 by 5000 matrix in full storage requires space for 25 million complex numbers even if only 50,000 are nonzero. The same 50,000-nonzero element matrix, in sparse storage, would store 50,000 complex numbers and 50,000 pairs of integer indices, less than .5% the space (less than one megabyte, instead of 200 meg). Similarly, solving Ma=b where M is such a matrix would take most of a day in full storage, and less than half a minute in sparse. Obviously if you are dealing with large, sparse matrices, you should take advantage of these features.

Some sparsity functions are useful for other purposes, as sparsity is connected to graph and tree theory.

See help sparse for a description of sparse storage mode, and help sparfun for a list of the sparse matrix functions. The MATLAB User's Guide (see gif Help) has (as usual) a much fuller description of the nature, uses, and manipulation of sparse matrices.



sepherke
Sat Mar 21 21:42:28 EST 1998