File: test12.m

package info (click to toggle)
suitesparse 1%3A3.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,788 kB
  • sloc: ansic: 106,134; cpp: 13,129; makefile: 6,679; fortran: 4,591; csh: 763; ruby: 603; perl: 236; sed: 164; awk: 29; sh: 8
file content (44 lines) | stat: -rw-r--r-- 957 bytes parent folder | download | duplicates (2)
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
function test12
%TEST12 test cs_qr and compare with svd
%
% Example:
%   test12
% See also: testall

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

fprintf ('test 12\n') ;
rand ('state',0) ;
% A = rand (3,4)

for trial = 1:100
    m = fix (100 * rand (1)) ;
    n = fix (100 * rand (1)) ;
    d = .1 * rand (1) ;
    A = sprandn (m,n,d) ;
    fprintf ('m %d n %d nnz %d\n', m, n, nnz(A)) ;
    if (m < n)
        continue ;
    end
    if (m == 0 | n == 0)                                                    %#ok
        continue ;
    end
    % save A A
    fprintf ('[ ') ;
    [V,Beta,p,R] = cs_qr (A) ;
    % [Q,R] = svd (full(A)) ;
    fprintf (']\n') ;

    s1 = svd (full (A)) ;
    s2 = svd (full (R)) ;
    s2 = s2 (1:length(s1)) ;
    err = norm (s1-s2) ; 
    if (length (s1) > 1)
        err = err / s1 (1) ;
    end
    fprintf ('err %g\n', err) ;
    if (err > 1e-12)
        error ('!') ;
    end
end