The function
has constructed a sparse matrix
(shown in computing diary A.1) from three vectors representing the row (
), column (
) and data (
) (see Eq. (A.12)). In this diary, the conversion of the sparse matrix
to a full matrix
(
) is shown.
octave:1> iv = [1 2 3 3 4 4 5 5 6 6 7 7 8 8]
iv =
1 2 3 3 4 4 5 5 6 6 7 7 8 8
octave:2> jv = [8 7 4 8 5 8 3 7 6 7 2 6 1 6]
jv =
8 7 4 8 5 8 3 7 6 7 2 6 1 6
octave:3> sv = [6 -6 -8 -10 8 -2 8 -10 -8 -2 -1 1 1 4]
sv =
6 -6 -8 -10 8 -2 8 -10 -8 -2 -1 1 1 4
octave:4> spA=sparse(iv, jv, sv)
spA =
Compressed Column Sparse (rows = 8, cols = 8, nnz = 14 [22%])
(8, 1) -> 1 (7, 2) -> -1 (5, 3) -> 8 (3, 4) -> -8 (4, 5) -> 8 (6, 6) -> -8 (7, 6) -> 1 (8, 6) -> 4 (2, 7) -> -6 (5, 7) -> -10 (6, 7) -> -2 (1, 8) -> 6 (3, 8) -> -10 (4, 8) -> -2
octave:5> A=full(spA)
A =
0 0 0 0 0 0 0 6
0 0 0 0 0 0 -6 0
0 0 0 -8 0 0 0 -10
0 0 0 0 8 0 0 -2
0 0 8 0 0 0 -10 0
0 0 0 0 0 -8 -2 0
0 -1 0 0 0 1 0 0
1 0 0 0 0 4 0 0
octave:6>
The non-zero elements of the matrix
of Eq. (A.11) can be represented as the matrix
with columns
,
and
, see Eq. (A.12):
The function
(given in computing diary A.2) constructs a sparse matrix
from the matrix
.
octave:1> A1=[1 8 6;
2 7 -6;
3 4 -8;
3 8 -10;
4 5 8;
4 8 -2;
5 3 8;
5 7 -10;
6 6 -8;
6 7 -2;
7 2 -1;
7 6 1;
8 1 1;
8 6 4]
A1 =
1 8 6
2 7 -6
3 4 -8
3 8 -10
4 5 8
4 8 -2
5 3 8
5 7 -10
6 6 -8
6 7 -2
7 2 -1
7 6 1
8 1 1
8 6 4
octave:2> spA=spconvert(A1) spA = Compressed Column Sparse (rows = 8, cols = 8, nnz = 14 [22%])
(8, 1) -> 1 (7, 2) -> -1 (5, 3) -> 8 (3, 4) -> -8 (4, 5) -> 8 (6, 6) -> -8 (7, 6) -> 1 (8, 6) -> 4 (2, 7) -> -6 (5, 7) -> -10 (6, 7) -> -2 (1, 8) -> 6 (3, 8) -> -10 (4, 8) -> -2
The function
converts the full matrix
to a sparse matrix (see computing diary A.3).
octave:6> A
A =
0 0 0 0 0 0 0 6
0 0 0 0 0 0 -6 0
0 0 0 -8 0 0 0 -10
0 0 0 0 8 0 0 -2
0 0 8 0 0 0 -10 0
0 0 0 0 0 -8 -2 0
0 -1 0 0 0 1 0 0
1 0 0 0 0 4 0 0
octave:7> spA=sparse(A) spA = Compressed Column Sparse (rows = 8, cols = 8, nnz = 14 [22%])
(8, 1) -> 1 (7, 2) -> -1 (5, 3) -> 8 (3, 4) -> -8 (4, 5) -> 8 (6, 6) -> -8 (7, 6) -> 1 (8, 6) -> 4 (2, 7) -> -6 (5, 7) -> -10 (6, 7) -> -2 (1, 8) -> 6 (3, 8) -> -10 (4, 8) -> -2
octave:8>