File: lintests.m

package info (click to toggle)
suitesparse 1%3A5.8.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 152,716 kB
  • sloc: ansic: 774,385; cpp: 24,213; makefile: 6,310; fortran: 1,927; java: 1,826; csh: 1,686; ruby: 725; sh: 535; perl: 225; python: 209; sed: 164; awk: 60
file content (69 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download | duplicates (5)
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
function lintests
%LINTESTS test linfactor with many different kinds of systems.
% Compares x=A\b, linfactor and (ack!) inv(A)*b.  You should never, ever use
% inv(A) to solve a linear system.
%
% Example
%   lintests
%
% See also lintest, linfactor, mldivide.

% Copyright 2007, Timothy A. Davis

rand ('state', 0) ;
help linfactor

for n = [100 1000 2000]

    fprintf ('\nn: %d (with all nonzero matrix A)\n', n) ;

    % dense LU
    A = rand (n) ;
    b = rand (n,1) ;
    lintest (A,b) ;

    % sparse LU
    A = sparse (A) ;
    lintest (A,b) ;

    % dense Cholesky
    A = A*A' + 10*eye(n) ;
    lintest (A,b) ;

    % sparse Cholesky
    A = sparse (A) ;
    lintest (A,b) ;

end

for n = [1000 2000]

    % note that UMFPACK is not particularly fast for tridiagonal matrices
    % (see "doc mldivide", which uses a specialized tridiagonal solver)
    fprintf ('\nn: %d (sparse tridiagonal matrix)\n', n) ;

    % sparse LU
    e = rand (n, 1) ;
    b = rand (n, 1) ;
    A = spdiags ([e 4*e e], -1:1, n, n) ;
    lintest (A,b) ;

    % sparse Cholesky
    e = ones (n, 1) ;
    A = spdiags ([e 4*e e], -1:1, n, n) ;
    lintest (A,b) ;

end

% sparse LU again
fprintf ('\nwest0479:\n') ;
load west0479 ;
n = size (west0479, 1) ;
b = rand (n, 1) ;
lintest (west0479, b) ;

% completely break inv(A) with a simple 2-by-2 matrix ...
fprintf ('\nbreak inv(A) with a trivial 2-by-2 matrix:\n') ;
s = warning ('off', 'MATLAB:singularMatrix') ;
lintest (rand(2) * realmin/2, ones(2,1)) ;
warning (s) ;