10. Sparse Matrices in MATLAB

Society for Industrial and Applied Mathematics eBooks · 2006

Almost all MATLAB operators and functions work seamlessly on both sparse and full matrices. It is possible to write an efficient MATLAB M-file that can operate on either full or sparse matrices with no changes to the code. In MATLAB, “sparse” is an attribute of the data structure used to represent a matrix. Sparsity propagates in MATLAB; if a function or operator has sparse operands, the result is usually sparse. A fixed set of rules determines the storage class (sparse or full) of the result. In general, unary functions and operators return a result of the same storage class as the input. For example, chol(A) is sparse if A is sparse and full otherwise. The result of a binary operator (A+B, for example) is sparse if both A and B are sparse and full if both A and B are full. If the operands are mixed, the result is usually full, unless the operation preserves sparsity ([A B], [A; B], and A.*B are sparse if either A or B are sparse, for example). The submatrix A (i, j) has the same type as A, unless it is a scalar (in which case A (i, j) is full). Submatrix assignment (A (i, j) = …) leaves the storage class of A unchanged.

Read the paper · More papers on PaperTik