A.1.3 Sparse matrix functions in the EST method

There are several functions that manipulate sparse matrices: full, sparse, spconvert, spfind, sprank, spy, speye, etc. A.8

We shall introduce the GNU Octave function spA=spInsertBtoA(spA,M,N,spB) (p. [*]) written for the EST method. This function inserts a sparse matrix spB into the sparse matrix spA, starting at row index M and column index N. The overlapping elements of the matrices spA and spB are added together.

The insertion of the matrix $\mathbf{B}$ (Eq. (A.14)) into the sparse matrix $\mathbf{spC}$ is described in computing diary A.4. There, the elements of the matrix C of value 2 (C(5,5) and C(6,6)) have been obtained as the sum of overlapped elements of matrices spB and spB1.

$\displaystyle \mathbf{B} = \left[ \begin{array}{cccccc}
1 & 0 & 0 & 0 & 0 & 0 \...
... 0 \\
0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1
\end{array}\right] \quad$     (A.14)

Computing diary A.4  
octave:1> iv = [1 2 3 4 5 6]
iv =

   1   2   3   4   5   6

octave:2> jv = [1 2 4 3 5 6]
jv =

   1   2   4   3   5   6

octave:3> sv = [1 1 1 1 1 1]
sv =sparse matrix spB

   1   1   1   1   1   1

octave:4> spB=sparse(iv, jv, sv)
spB =

Compressed Column Sparse (rows = 6, cols = 6, nnz = 6 [17%])

  (1, 1) ->  1
  (2, 2) ->  1
  (4, 3) ->  1                                                                                                                                                
  (3, 4) ->  1                                                                                                                                                
  (5, 5) ->  1                                                                                                                                                
  (6, 6) ->  1                                                                                                                                                
                                                                                                                                                              
octave:5> spB1=spB;                                                                                                                                        
octave:6> spC=sparse(10,10)                                                                                                                                   
spC =                                                                                                                                                         
                                                                                                                                                              
Compressed Column Sparse (rows = 10, cols = 10, nnz = 0 [0%])                                                                                                 
                                                                                                                                                              
                                                                                                                                                              
octave:7> spC=spInsertBtoA(spC,1,1,spB);                                                                                                                      
octave:8> spC=spInsertBtoA(spC,5,5,spB1)                                                                                                                       
spC =                                                                                                                                                         
                                                                                                                                                              
Compressed Column Sparse (rows = 10, cols = 10, nnz = 10 [10%])                                                                                               
                                                                                                                                                              
  (1, 1) ->  1                                                                                                                                                
  (2, 2) ->  1                                                                                                                                                
  (4, 3) ->  1                                                                                                                                                
  (3, 4) ->  1                                                                                                                                                
  (5, 5) ->  2                                                                                                                                                
  (6, 6) ->  2                                                                                                                                                
  (8, 7) ->  1                                                                                                                                                
  (7, 8) ->  1                                                                                                                                                
  (9, 9) ->  1                                                                                                                                                
  (10, 10) ->  1                                                                                                                                              
                                                                                                                                                              
octave:9> C=full(spC)                                                                                                                                         
C =

   1   0   0   0   0   0   0   0   0   0
   0   1   0   0   0   0   0   0   0   0
   0   0   0   1   0   0   0   0   0   0
   0   0   1   0   0   0   0   0   0   0
   0   0   0   0   2   0   0   0   0   0
   0   0   0   0   0   2   0   0   0   0
   0   0   0   0   0   0   0   1   0   0
   0   0   0   0   0   0   1   0   0   0
   0   0   0   0   0   0   0   0   1   0
   0   0   0   0   0   0   0   0   0   1

octave:10>


Next we introduce the GNU Octave function spA=spSisestaArv(spA,M,N,V) (p. [*]) written for the EST method. This function inserts a numeric value $\mathbf{V}$ into the sparse matrix spA at row index M and column index N.

andres
2014-09-09