File: lintests.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (70 lines) | stat: -rw-r--r-- 1,582 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
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
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.

% LINFACTOR, Copyright (c) 2008, Timothy A Davis. All Rights Reserved.
% SPDX-License-Identifier: BSD-3-clause

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) ;