% operations with sparse matrices 

echo on;

% initializing a sparse matrix 
row = [ 5;  9;  1;  1;  8;  5;  7;  6;  5];
col = [ 3;  4;  1;  3;  5;  3;  1;  2;  4];
val = [.3; .1; .7; .9; .2; .8; .4; .5; .3]; 

s = sparse(row, col, val), pause;

% visualizing the sparsity pattern
full(s), spy(s), pause; 

% fill in for sparse matrix multiplication
s1 = sprand(100,100,3/100);
s2 = s1*s1; 
subplot(1,2,1); spy(s1); 
subplot(1,2,2); spy(s2);
pause;

% sparse rank and rank 
[sprank(s1), sprank(s2); rank(full(s1)), rank(full(s2))],
pause;

echo off;

