Previous Up Next

14.4.3  Operations on sparse matrices

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

Example

Create some sparse matrices.

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

0,0
1

1,1
2

2,2
3
          
purge(B):; B[0..1,1..2]:=[1,2]:; B[0..2,0]:=5
     
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.

A+B
     
KeyValue

0,0
6

0,1
1

1,0
5

1,1
2

1,2
2

2,0
5

2,2
3
          
A*B
     
KeyValue

0,0
5

0,1
1

1,0
10

1,2
4

2,0
15
          
2*A
     
KeyValue

0,0
2

1,1
4

2,2
6
          

Previous Up Next