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

« back to all changes in this revision

Viewing changes to UMFPACK/MATLAB/umfpack_demo.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
 
function umfpack_demo
2
 
% UMFPACK DEMO
 
1
function umfpack_demo (c)
 
2
%UMFPACK_DEMO a lenghty demo
3
3
%
4
4
% A demo of UMFPACK for MATLAB.
5
5
%
6
 
% See also umfpack, umfpack_make, umfpack_details, umfpack_report,
 
6
% Example:
 
7
%   umfpack_demo
 
8
%
 
9
% See also umfpack, umfpack2, umfpack_make, umfpack_details, umfpack_report,
7
10
% and umfpack_simple.
8
11
 
9
 
% UMFPACK Version 5.0, Copyright (c) 1995-2006 by Timothy A. Davis.
10
 
% All Rights Reserved.  Type umfpack_details for License.
 
12
% Copyright 1995-2007 by Timothy A. Davis.
11
13
 
12
14
%-------------------------------------------------------------------------------
13
15
% get default control parameters
14
16
%-------------------------------------------------------------------------------
15
17
 
16
 
control = umfpack ;
17
 
fprintf ('\nEnter the printing level for UMFPACK''s output statistics:\n') ;
18
 
fprintf ('0: none, 1: errors only, 2: statistics, 4: print some of outputs\n') ;
19
 
c = input ('5: print all output [default is 1]: ') ;
 
18
control = umfpack2 ;
 
19
if (nargin < 1)
 
20
    fprintf ('\nEnter the printing level for UMFPACK''s output statistics:\n') ;
 
21
    fprintf ('0: none, 1: errors only, 2: statistics, 4: print some outputs\n');
 
22
    c = input ('5: print all output [default is 1]: ', 's') ;
 
23
    c = str2double (c) ;
 
24
end
20
25
if (isempty (c))
21
26
    c = 1 ;
22
27
end
39
44
b = rand (n, 1) ;
40
45
 
41
46
fprintf ('Solving Ax=b via UMFPACK:\n') ;
42
 
[xu, info] = umfpack (A, '\', b, control) ;
43
 
x = xu ;
 
47
xu = umfpack2 (A, '\', b, control) ;
44
48
 
45
49
fprintf ('Solving Ax=b via MATLAB:\n') ;
46
50
xm = A\b ;
47
 
x = xm ;
48
51
 
49
52
fprintf ('Difference between UMFPACK and MATLAB solution: %g\n', ...
50
53
    norm (xu - xm, Inf)) ;
61
64
title ('The matrix A') ;
62
65
 
63
66
subplot (2,3,2)
64
 
[P1, Q1, Fr, Ch, Info] = umfpack (A, 'symbolic') ;
 
67
[P1, Q1, Fr, Ch, Info] = umfpack2 (A, 'symbolic') ;                         %#ok
65
68
treeplot (Fr (1:end-1,2)') ;
66
69
title ('Supernodal column elimination tree') ;
67
70
 
71
74
 
72
75
subplot (2,3,4)
73
76
fprintf ('\n--------------------------------------------------------------\n') ;
74
 
fprintf ('\nFactorizing [L, U, P, Q, R] = umfpack (A)\n') ;
75
 
[L, U, P, Q, R] = umfpack (A) ;
 
77
fprintf ('\nFactorizing [L, U, P, Q, R] = umfpack2 (A)\n') ;
 
78
[L, U, P, Q, R] = umfpack2 (A) ;
76
79
spy (P*A*Q)
77
80
title ('A, with final row/column order') ;
78
81
 
83
86
fprintf ('\nSolution to Ax=b via UMFPACK factorization:\n') ;
84
87
fprintf ('x = Q * (U \\ (L \\ (P * (R \\ b))))\n') ;
85
88
xu = Q * (U \ (L \ (P * (R \ b)))) ;
86
 
x = xu ;
87
89
 
88
90
fprintf ('\nUMFPACK flop count: %d\n', luflop (L, U)) ;
89
91
 
126
128
fprintf ('Solve A''x=b:\n') ;
127
129
 
128
130
fprintf ('Solving A''x=b via UMFPACK:\n') ;
129
 
[xu, info] = umfpack (b', '/', A, control) ;
 
131
xu = umfpack2 (b', '/', A, control) ;
130
132
xu = xu' ;
131
133
 
132
134
fprintf ('Solving A''x=b via MATLAB:\n') ;
133
135
xm = (b'/A)' ;
134
 
x = xm ;
135
136
 
136
137
fprintf ('Difference between UMFPACK and MATLAB solution: %g\n', ...
137
138
    norm (xu - xm, Inf)) ;
149
150
C = A' ;
150
151
 
151
152
% factorize C (P,Q) = L*U
152
 
[L, U, P, Q, R, info] = umfpack (C, control) ;
 
153
[L, U, P, Q, R, info] = umfpack2 (C, control) ;                             %#ok
153
154
 
154
155
fprintf ('\nP * (R\\C) * Q - L*U should be zero:\n') ;
155
156
fprintf ('norm (P*(R\\C)*Q - L*U, 1) = %g (exact) %g (estimated)\n', ...
158
159
fprintf ('\nSolution to Ax=b via UMFPACK, using the factors of C:\n') ;
159
160
fprintf ('x = R \\ (P'' * (L'' \\ (U'' \\ (Q'' * b)))) ;\n') ;
160
161
xu = R \ (P' * (L' \ (U' \ (Q' * b)))) ;
161
 
x = xu ;
162
162
 
163
163
fprintf ('Solution to Ax=b via MATLAB:\n') ;
164
164
xm = A\b ;
165
 
x = xm ;
166
165
 
167
166
fprintf ('Difference between UMFPACK and MATLAB solution: %g\n', ...
168
167
    norm (xu - xm, Inf)) ;
200
199
%-------------------------------------------------------------------------------
201
200
 
202
201
fprintf ('\n--------------------------------------------------------------\n') ;
203
 
fprintf ('det(A): %g  UMFPACK determinant: %g\n', det (A), umfpack (A, 'det')) ;
 
202
fprintf ('det(A): %g  UMFPACK determinant: %g\n', det (A), umfpack2 (A, 'det'));