%
% Working with sparse matrices in Matlab....
%

function test_sparse()
%
% Test matrix in sparse coordinate format:
%
my_matrix = [...
    1 1 5.0;
    2 2 -10.0;
    3 2 1.0;
    3 3 15.0;
    4 1 -0.2;
    4 4 0.5;
    5 3 0.1;
    5 5 2.0;
    6 1 -1.0;
    6 5 -3.0;
    6 6 1.5
    ];

L = spconvert(my_matrix);  % convert to Matlab's internal format

full(L)    % just for debug (does not make any sense for big matrix ;-)

spy(L)   % visualize the sparsity pattern

b=ones(6,1);
%
% Solve sparse system using Matlab's internal sparse solver:
%
x=L\b;
x'

% The same matrix in CSC format:

s   = [ 5. -0.2 -1. -10. 1. 15. 0.1 0.5 2. -3. 1.5];
row = [ 1   4    6    2  3   3   5   4  5   6   6];
colptr = [ 1 4 6 8 9 11 12 ];
%
% Solve sparse system using our own sparse lower triangular solver:
%
x2=solve_sparse_tri(s,row,colptr,b);
x2';

