Language Reference


SPARSE Function

SPARSE (x <, type> );

The SPARSE function converts an $n\times p$ 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:

x

specifies an $n\times p$ numerical matrix. Typically, x contains many zeros and only k nonzeros, where k is much smaller than $np$.

type

specifies whether the x matrix is symmetric. The following values are valid:

"symmetric"

specifies that only the lower triangular nonzero values of the x matrix are used.

"unsymmetric"

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 $k \times 3$ 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.380: 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