Previous Up Next

6.46.2  Operations on sparse matrices

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


Example.
Create some sparse matrices.
Input:

purge(A):;
A[0..2,0..2]:= [1,2,3]

Output:

KeyValue

0,0
1

1,1
2

2,2
3

Input:

purge(B):;
B[0..1,1..2]:= [1,2]:;
B[0..2,0]:=5

Output:

KeyValue

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:

KeyValue

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:

KeyValue

0,0
5

0,1
1

1,0
10

1,2
4

2,0
15

Input:

2*A

Output:

KeyValue

0,0
2

1,1
4

2,2
6

Previous Up Next