1
function cs_demo1 (matrixpath)
2
%CS_DEMO1 MATLAB version of the CSparse/Demo/cs_demo1.c program.
3
% Uses both MATLAB functions and CSparse mexFunctions, and compares the two
4
% results. This demo also plots the results, which the C version does not do.
10
% Copyright 2006-2007, Timothy A. Davis.
11
% http://www.cise.ufl.edu/research/sparse
17
if (isempty (matrixpath))
19
% older versions of MATLAB do not have an input argument to mfilename
20
p = mfilename ('fullpath') ;
21
t = strfind (p, filesep) ;
22
matrixpath = [ p(1:t(end)) '../../Matrix' ] ;
24
% assume we are in the C*Sparse/MATLAB/CSparse/Demo directory
25
matrixpath = '../../Matrix' ;
29
t1 = load ([matrixpath '/t1']) ;
32
A = sparse (T(:,1)+1, T(:,2)+1, T(:,3)) %#ok
33
A2 = cs_sparse (T(:,1)+1, T(:,2)+1, T(:,3)) %#ok
34
fprintf ('A difference: %g\n', norm (A-A2,1)) ;
35
% CSparse/Demo/cs_demo1.c also clears the triplet matrix T at this point:
38
subplot (2,2,1) ; cspy (A) ; title ('A', 'FontSize', 16) ;
40
AT2 = cs_transpose (A) %#ok
41
fprintf ('AT difference: %g\n', norm (AT-AT2,1)) ;
42
subplot (2,2,2) ; cspy (AT) ; title ('A''', 'FontSize', 16) ;
46
C2 = cs_multiply (A, AT) %#ok
47
fprintf ('C difference: %g\n', norm (C-C2,1)) ;
48
subplot (2,2,3) ; cspy (C) ; title ('C=A*A''', 'FontSize', 16) ;
51
D2 = cs_add (C, I, 1, cnorm) %#ok
52
fprintf ('D difference: %g\n', norm (D-D2,1)) ;
53
subplot (2,2,4) ; cspy (D) ; title ('D=C+I*norm(C,1)', 'FontSize', 16) ;
54
% CSparse/Demo/cs_demo1.c clears all matrices at this point: