File: test3.m

package info (click to toggle)
suitesparse-metis 3.1.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 36,560 kB
  • ctags: 7,484
  • sloc: ansic: 104,515; makefile: 5,984; fortran: 4,591; sh: 1,397; csh: 739; ruby: 603; perl: 219; sed: 164; awk: 18
file content (97 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function test3
%TEST3 test cs_lsolve, cs_ltsolve, cs_usolve, cs_chol
%
% Example:
%   test3
% See also: testall

%   Copyright 2006-2007, Timothy A. Davis.
%   http://www.cise.ufl.edu/research/sparse

index = UFget ;
[ignore f] = sort (max (index.nrows, index.ncols)) ;
f = f (1:100) ;

clf
% f = f(1)

for i = f
    Prob = UFget (i) ;
    disp (Prob) ;
    A = Prob.A ;
    [m n] = size (A) ;
    if (~isreal (A) | m ~= n)						    %#ok
	continue
    end

    A = A*A' + 2*n*speye (n) ;
    try
	p = amd (A) ;
    catch
	p = symamd (A) ;
    end
    try
	L0 = chol (A)' ;
    catch
	continue
    end
    b = rand (n,1) ;

    C = A(p,p) ;
    c = condest (C) ;
    fprintf ('condest: %g\n', c) ;

    x1 = L0\b ;
    x2 = cs_lsolve (L0,b) ;
    err = norm (x1-x2,1) ;
    if (err > 1e-12 * c)
	error ('!') ;
    end

    x1 = L0'\b ;
    x2 = cs_ltsolve (L0,b) ;
    err = norm (x1-x2,1) ;
    if (err > 1e-10 * c)
	error ('!') ;
    end

    U = L0' ;

    x1 = U\b ;
    x2 = cs_usolve (U,b) ;
    err = norm (x1-x2,1) ;
    if (err > 1e-10 * c)
	error ('!') ;
    end

    L2 = cs_chol (A) ;
    subplot (2,3,1) ; spy (L0) ;
    subplot (2,3,4) ; spy (L2) ;
    err = norm (L0-L2,1) ;
    if (err > 1e-8 * c)
	error ('!') ;
    end

    L1 = chol (C)' ;
    L2 = cs_chol (C) ;
    subplot (2,3,2) ; spy (L1) ;
    subplot (2,3,5) ; spy (L2) ;
    err = norm (L1-L2,1) ;
    if (err > 1e-8 * c)
	error ('!') ;
    end

    [L3,p] = cs_chol (A) ;
    C = A(p,p) ;
    L4 = chol (C)' ;
    subplot (2,3,3) ; spy (L4) ;
    subplot (2,3,6) ; spy (L3) ;
    err = norm (L4-L3,1) ;
    if (err > 1e-8 * c)
	error ('!') ;
    end

    drawnow

end