~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to CXSparse_newfiles/MATLAB/Test/test3.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 test3
 
2
%TEST3 test cs_lsolve, cs_ltsolve, cs_usolve, cs_chol
 
3
%
 
4
% Example:
 
5
%   test3
 
6
% See also: testall
 
7
 
 
8
%   Copyright 2006-2007, Timothy A. Davis.
 
9
%   http://www.cise.ufl.edu/research/sparse
 
10
 
 
11
clear
 
12
index = UFget ;
 
13
[ignore f] = sort (max (index.nrows, index.ncols)) ;
 
14
f = f (1:100) ;
 
15
 
 
16
clf
 
17
% f = f(1)
 
18
 
 
19
for i = f
 
20
 
 
21
    Prob = UFget (i) ;
 
22
    disp (Prob) ;
 
23
 
 
24
    for cmplex = 0:1
 
25
 
 
26
        A = Prob.A ;
 
27
        [m n] = size (A) ;
 
28
        if (m ~= n)
 
29
            continue
 
30
        end
 
31
 
 
32
        if (cmplex)
 
33
            A = A + 1i*sprand(A) ;
 
34
        end
 
35
 
 
36
        A = A*A' + 2*n*speye (n) ;
 
37
        try
 
38
            p = amd (A) ;
 
39
        catch
 
40
            p = symamd (A) ;
 
41
        end
 
42
        try
 
43
            L0 = chol (A)' ;
 
44
        catch
 
45
            continue
 
46
        end
 
47
        b = rand (n,1) ;
 
48
        if (mod (i,2) == 1)
 
49
            b = b + 1i*rand(n,1) ;
 
50
        end
 
51
 
 
52
        C = A(p,p) ;
 
53
        c = condest (C) ;
 
54
        fprintf ('condest: %g\n', c) ;
 
55
 
 
56
        x1 = L0\b ;
 
57
        x2 = cs_lsolve (L0,b) ;
 
58
        err = norm (x1-x2,1) ;
 
59
        if (err > 1e-12 * c)
 
60
            error ('!') ;
 
61
        end
 
62
 
 
63
        x1 = L0'\b ;
 
64
        x2 = cs_ltsolve (L0,b) ;
 
65
        err = norm (x1-x2,1) ;
 
66
        if (err > 1e-10 * c)
 
67
            error ('!') ;
 
68
        end
 
69
 
 
70
        U = L0' ;
 
71
 
 
72
        x1 = U\b ;
 
73
        x2 = cs_usolve (U,b) ;
 
74
        err = norm (x1-x2,1) ;
 
75
        if (err > 1e-10 * c)
 
76
            error ('!') ;
 
77
        end
 
78
 
 
79
        L2 = cs_chol (A) ;
 
80
        subplot (2,3,1) ; spy (L0) ;
 
81
        subplot (2,3,4) ; spy (L2) ;
 
82
        err = norm (L0-L2,1) ;
 
83
        if (err > 1e-8 * c)
 
84
            error ('!') ;
 
85
        end
 
86
 
 
87
        L1 = chol (C)' ;
 
88
        L2 = cs_chol (C) ;
 
89
        subplot (2,3,2) ; spy (L1) ;
 
90
        subplot (2,3,5) ; spy (L2) ;
 
91
        err = norm (L1-L2,1) ;
 
92
        if (err > 1e-8 * c)
 
93
            error ('!') ;
 
94
        end
 
95
 
 
96
        [L3,p] = cs_chol (A) ;
 
97
        C = A(p,p) ;
 
98
        L4 = chol (C)' ;
 
99
        subplot (2,3,3) ; spy (L4) ;
 
100
        subplot (2,3,6) ; spy (L3) ;
 
101
        err = norm (L4-L3,1) ;
 
102
        if (err > 1e-8 * c)
 
103
            error ('!') ;
 
104
        end
 
105
 
 
106
        drawnow
 
107
 
 
108
    end
 
109
end