1
function umfpack_demo (c)
2
%UMFPACK_DEMO a lenghty demo
4
4
% A demo of UMFPACK for MATLAB.
6
% See also umfpack, umfpack_make, umfpack_details, umfpack_report,
9
% See also umfpack, umfpack2, umfpack_make, umfpack_details, umfpack_report,
7
10
% and umfpack_simple.
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.
12
14
%-------------------------------------------------------------------------------
13
15
% get default control parameters
14
16
%-------------------------------------------------------------------------------
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]: ') ;
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') ;
41
46
fprintf ('Solving Ax=b via UMFPACK:\n') ;
42
[xu, info] = umfpack (A, '\', b, control) ;
47
xu = umfpack2 (A, '\', b, control) ;
45
49
fprintf ('Solving Ax=b via MATLAB:\n') ;
49
52
fprintf ('Difference between UMFPACK and MATLAB solution: %g\n', ...
50
53
norm (xu - xm, Inf)) ;
61
64
title ('The matrix A') ;
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') ;
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) ;
77
80
title ('A, with final row/column order') ;
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)))) ;
88
90
fprintf ('\nUMFPACK flop count: %d\n', luflop (L, U)) ;
126
128
fprintf ('Solve A''x=b:\n') ;
128
130
fprintf ('Solving A''x=b via UMFPACK:\n') ;
129
[xu, info] = umfpack (b', '/', A, control) ;
131
xu = umfpack2 (b', '/', A, control) ;
132
134
fprintf ('Solving A''x=b via MATLAB:\n') ;
136
137
fprintf ('Difference between UMFPACK and MATLAB solution: %g\n', ...
137
138
norm (xu - xm, Inf)) ;
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
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)))) ;
163
163
fprintf ('Solution to Ax=b via MATLAB:\n') ;
167
166
fprintf ('Difference between UMFPACK and MATLAB solution: %g\n', ...
168
167
norm (xu - xm, Inf)) ;
200
199
%-------------------------------------------------------------------------------
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'));