Documentation

Sparse Matrices

Elementary sparse matrices, reordering algorithms, iterative methods, sparse linear algebra

Sparse matrices provide efficient storage of double or logical data that has a large percentage of zeros. While full (or dense) matrices store every single element in memory regardless of value, sparse matrices store only the nonzero elements and their row indices. For this reason, using sparse matrices can significantly reduce the amount of memory required for data storage.

All MATLAB® built-in arithmetic, logical, and indexing operations can be applied to sparse matrices, or to mixtures of sparse and full matrices. Operations on sparse matrices return sparse matrices and operations on full matrices return full matrices. For more information, see Computational Advantages of Sparse Matrices and Constructing Sparse Matrices.

Functions

expand all

 spalloc Allocate space for sparse matrix spdiags Extract nonzero diagonals and create sparse band and diagonal matrices speye Sparse identity matrix sprand Sparse uniformly distributed random matrix sprandn Sparse normally distributed random matrix sprandsym Sparse symmetric random matrix sparse Create sparse matrix spconvert Import from sparse matrix external format
 issparse Determine whether input is sparse nnz Number of nonzero matrix elements nonzeros Nonzero matrix elements nzmax Amount of storage allocated for nonzero matrix elements spfun Apply function to nonzero sparse matrix elements spones Replace nonzero sparse matrix elements with ones spparms Set parameters for sparse matrix routines spy Visualize sparsity pattern of matrix find Find indices and values of nonzero elements full Convert sparse matrix to full storage
 dissect Nested dissection permutation amd Approximate minimum degree permutation colamd Column approximate minimum degree permutation colperm Sparse column permutation based on nonzero count dmperm Dulmage-Mendelsohn decomposition randperm Random permutation of integers symamd Symmetric approximate minimum degree permutation symrcm Sparse reverse Cuthill-McKee ordering
 pcg Preconditioned conjugate gradients method minres Minimum residual method symmlq Symmetric LQ method gmres Generalized minimum residual method (with restarts) bicg Biconjugate gradients method bicgstab Biconjugate gradients stabilized method bicgstabl Biconjugate gradients stabilized (l) method cgs Conjugate gradients squared method qmr Quasi-minimal residual method tfqmr Transpose-free quasi-minimal residual method lsqr LSQR method equilibrate Matrix scaling for improved conditioning ichol Incomplete Cholesky factorization ilu Incomplete LU factorization
 eigs Subset of eigenvalues and eigenvectors svds Subset of singular values and vectors normest 2-norm estimate condest 1-norm condition number estimate
 sprank Structural rank etree Elimination tree symbfact Symbolic factorization analysis spaugment Form least-squares augmented system dmperm Dulmage-Mendelsohn decomposition etreeplot Plot elimination tree treelayout Lay out tree or forest treeplot Plot picture of tree gplot Plot nodes and edges in adjacency matrix unmesh Convert edge matrix to coordinate and Laplacian matrices

Topics

Constructing Sparse Matrices

Storing sparse data as a matrix.

Computational Advantages of Sparse Matrices

Advantages of sparse matrices over full matrices.

Accessing Sparse Matrices

Indexing and visualizing sparse data.

Sparse Matrix Operations

Reordering, factoring, and computing with sparse matrices.

Sparse Matrix Reordering

This example shows how reordering the rows and columns of a sparse matrix can influence the speed and storage requirements of a matrix operation.

Graphs and Matrices

This example shows an application of sparse matrices and explains the relationship between graphs and matrices.