The SPARSE function converts an matrix that contains many zeros into a matrix stored in a sparse format which suitable for use with the ITSOLVER call or the SOLVELIN call.
The arguments to the SPARSE function are as follows:
specifies an numerical matrix. Typically, x contains many zeros and only nonzeros, where is much smaller than .
specifies whether the x matrix is symmetric. The following values are valid:
specifies that only the lower triangular nonzero values of the x matrix are used.
specifies that all nonzero values of the x matrix are used. This is the default value.
The type argument is not case-sensitive. The first three characters are used to determine the value. For example, “SYM” and “symmetric” specify the same option.
The matrix returned by the SPARSE function is a matrix that contains the folling values:
The first column contains the nonzero values of the x matrix.
The second column contains the row numbers for each value.
The third column contains the column numbers for each value.
For example, the following statements compute a sparse representation of a dense matrix with many zeros:
x = {3 1.1 0 0 , 1.1 4 0 3.2, 0 1 10 0 , 0 3.2 0 3 }; a = sparse(x, "sym"); print a[colname={"Value" "Row" "Col"}];
Figure 24.378: Sparse Data Representation
a | ||
---|---|---|
Value | Row | Col |
3 | 1 | 1 |
1.1 | 2 | 1 |
4 | 2 | 2 |
1 | 3 | 2 |
10 | 3 | 3 |
3.2 | 4 | 2 |
3 | 4 | 4 |