Previous Up Next

5.50.2  Operations on sparse matrices

All matrix operations can be done on tables that are used to define sparse matrices.
Input:

purge(A), purge(B)

Input:

A[0..2,0..2] := [1,2,3]

Output:

table((0,0) = 1, (1,1) = 2, (2,2) = 3)

Input:

B[0..1,1..2] := [1,2]

Input:

B[0..2,0]:=5

Output:

table((0,0) = 5, (0,1) = 1, (1,0) = 5, (1,2) = 2, (2,0) = 5)

The usual operations will work on A and B.
Input:

A + B

Output:

table((0,0) = 6, (0,1) = 1, (1,0) = 5, (1,1) = 2, (1,2) = 2, (2,0) = 5, (2,2) = 3)

Input:

A * B

Output:

table((0,0) = 5, (0,1) = 1, (1,0) = 10, (1,2) = 4, (2,0) = 15)

Input:

2*A

Output:

table((0,0) = 2, (1,1) = 4, (2,2) = 6)

Previous Up Next