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

« back to all changes in this revision

Viewing changes to KLU/MATLAB/Test/test1.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
%test1: KLU test script
 
2
% Example:
 
3
%   test1
 
4
%
 
5
% See also klu
 
6
 
 
7
% Copyright 2004-2007 Timothy A. Davis, Univ. of Florida
 
8
% http://www.cise.ufl.edu/research/sparse
 
9
 
 
10
clear all
 
11
clear functions
 
12
rand ('state', 0) ;
 
13
 
 
14
index = UFget ;
 
15
f = find (index.nrows == index.ncols & index.isReal) ;
 
16
[ignore i] = sort (index.nnz (f)) ;
 
17
f = f (i) ;
 
18
 
 
19
 
 
20
f = f (1:100) ;
 
21
 
 
22
% f = 274
 
23
% f = 101       ; % MATLAB condest is poor
 
24
 
 
25
nmat = length (f) ;
 
26
 
 
27
conds_klu = ones (1,nmat) ;
 
28
conds_matlab = ones (1,nmat) ;
 
29
 
 
30
for k = 1:nmat
 
31
    i = f (k) ;
 
32
    try
 
33
        c = -1 ;
 
34
        blocks = 0 ;
 
35
        rho = 0 ;
 
36
        c2 = 0 ;
 
37
        r1 = 0 ;
 
38
        r2 = 0 ;
 
39
        err = 0 ;
 
40
 
 
41
        Prob = UFget (i,index) ;
 
42
        A = Prob.A ;
 
43
        c = condest (A) ;
 
44
        % klu (A)
 
45
        % [L,U,p,q,R,F,r,info] = klu (A) ;
 
46
 
 
47
        [LU, info, c2] = klu (A) ;
 
48
 
 
49
        L = LU.L ;
 
50
        U = LU.U ;
 
51
        p = LU.p ;
 
52
        q = LU.q ;
 
53
        R = LU.R ;
 
54
        F = LU.F ;
 
55
        r = LU.r ;
 
56
        blocks = length (r) - 1 ;
 
57
 
 
58
        n = size (A,1) ;
 
59
        b = rand (n,1) ;
 
60
        x = klu (LU,'\',b) ;
 
61
        err = norm (A*x-b,1) / norm (A,1) ;
 
62
 
 
63
        % info
 
64
        rho = lu_normest (R\A(p,q) - F, L, U) ;
 
65
        r1 = info.rcond ;
 
66
        r2 = full (min (abs (diag (U))) / max (abs (diag (U)))) ;
 
67
 
 
68
        if (r1 ~= r2)
 
69
            fprintf ('!\n') ;
 
70
            pause
 
71
        end
 
72
 
 
73
        conds_klu (k) = c2 ;
 
74
        conds_matlab (k) = c ;
 
75
 
 
76
    catch
 
77
        disp (lasterr) ;
 
78
    end
 
79
 
 
80
    fprintf (...
 
81
'blocks %6d err %8.2e condest %8.2e %8.2e rcond %8.2e %8.2e err %8.2e\n', ...
 
82
    blocks, rho, c2, c, r1, r2, err) ;
 
83
 
 
84
end
 
85
k = nmat ;
 
86
plot (1:k, log10 (conds_klu (1:k) ./ conds_matlab (1:k)), 'o') ;
 
87
drawnow