~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse/MATLAB/Demo/cs_demo1.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
%
 
6
% Example:
 
7
%   cs_demo1
 
8
% See also: cs_demo
 
9
 
 
10
%   Copyright 2006-2007, Timothy A. Davis.
 
11
%   http://www.cise.ufl.edu/research/sparse
 
12
 
 
13
if (nargin < 1)
 
14
    matrixpath = [] ;
 
15
end
 
16
 
 
17
if (isempty (matrixpath))
 
18
    try
 
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' ] ;
 
23
    catch
 
24
        % assume we are in the C*Sparse/MATLAB/CSparse/Demo directory
 
25
        matrixpath = '../../Matrix' ;
 
26
    end
 
27
end
 
28
 
 
29
t1 = load ([matrixpath '/t1']) ;
 
30
 
 
31
T = t1                                                                      %#ok
 
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:
 
36
% clear T 
 
37
clf
 
38
subplot (2,2,1) ; cspy (A) ; title ('A', 'FontSize', 16) ;
 
39
AT = A'                                                                     %#ok
 
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) ;
 
43
n = size (A,2) ;
 
44
I = speye (n) ;
 
45
C = A*AT ;
 
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) ;
 
49
cnorm = norm (C,1) ;
 
50
D = C + I*cnorm                                                             %#ok
 
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:
 
55
% clear A AT C D I
 
56
% clear A2 AT2 C2 D2