Sunday, July 3, 2022

Casio fx-CG50: Sparse Matrix Builder

Casio fx-CG50: Sparse Matrix Builder



Introduction


The programs can create a sparse matrix, a matrix where most of the entries have zero value.  There are several ways to represent sparse matrix in a shortcut form.  The most straight forward way is the COO (row-column-value) representation.


Mat A:  three column matrix:  (row-column-value representation)

Column 1:  row number

Column 2:  column number

Column 3:  value


Mat S:  sparse matrix


Casio fx-CG 50 Program:  SPARSE

[ [ row, column, value ] ... ] → sparse matrix


"TO SPARSE MATRIX"

"EDWARD SHORE"

"[[ROW,COL,VALUE]]"

"MAT"?→Mat A

Mat→List(Mat A,1)→List 26

Max(List 26)→R

Mat→List(Mat A,2)→List 26

Max(List 26)→C

{R,C}→Dim Mat S

Dim Mat A→List 26

List 26[1]→N

For 1→I To N

Mat A[I,1]→J

Mat A[I,2]→K

Mat A[I,3]→Mat S[J,K]

Next 

"SPARSE MATRIX:"⊿

Mat S


Casio fx-CG 50 Program: ISPARSE

sparse matrix → [ [ row, column, value ] ... ] 


"INV SPARSE MATRIX"

"EDWARD SHORE"

"SPARSE"?→Mat S

Dim Mat S→List 26

List 26[1]→R

List 26[2]→C

0→N

For 1→I To R

For 1→J To C

Mat S[I,J] →V

[[I][J][V]]→Mat Z

(V≠0 And N=0)⇒Mat Z→Mat A

(V≠0 And N>0)⇒Augment(Mat A,Mat Z)→Mat A

(V≠0)⇒1+N→N

Next

Next

"COO FORMAT:"⊿

Trn Mat A→Mat A


Example


Example 1:


Row/Column/Value (COO) Format:  (Mat A)


[ [ 1, 2, 8 ]

[ 2, 4, -3 ]

[ 3, 1, 2 ]

[ 3, 3, 6 ]

[ 4, 2, -1 ] ]


Sparse Matrix:  (Mat S)


[ [ 0, 8, 0, 0 ]

[ 0, 0, 0, -3 ]

[ 2, 0, 6, 0 ]

[ 0, -1, 0, 0 ] ]


Example 2:


Row/Column/Value (COO) Format:  (Mat A)


[ [ 1, 2, 1 ]

[ 1, 3, 2 ]

[ 2, 1, -1 ]

[ 2, 3, 3 ]

[ 3, 3, 4 ]

[ 4, 1, 5 ] ]


Sparse Matrix:  (Mat S)


[ [ 0, 1, 2 ] 

[-1, 0, 3 ] 

[ 0, 0, 4 ]

[ 5, 0, 0 ] ]


Source:


"Sparse matrix"  Wikipedia. Last edited March 11, 2022.  Accessed May 9, 2022.  https://en.wikipedia.org/wiki/Sparse_matrix


Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.