5164
|
1 function amd_demo |
|
2 % AMD DEMO |
|
3 % |
|
4 % A demo of AMD for OCTAVE. |
|
5 % |
|
6 % -------------------------------------------------------------------------- |
|
7 % AMD Version 1.1 (Jan. 21, 2004), Copyright (c) 2004 by Timothy A. Davis, |
|
8 % Patrick R. Amestoy, and Iain S. Duff. See ../README for License. |
|
9 % email: davis@cise.ufl.edu CISE Department, Univ. of Florida. |
|
10 % web: http://www.cise.ufl.edu/research/sparse/amd |
|
11 % -------------------------------------------------------------------------- |
|
12 % |
|
13 % See also: amd |
|
14 |
|
15 % Get the Harwell/Boeing can_24 matrix. This is an example matrix from the |
|
16 % MATLAB-accessible UF sparse matrix collection, and can be loaded into |
|
17 % MATLAB with the statment "Problem = UFget ('HB/can_24')", after obtaining |
|
18 % the UFget function and its supporting routines at |
|
19 % http://www.cise.ufl.edu/sparse/mat . |
|
20 |
|
21 load can_24.mat |
|
22 A = Problem.A ; |
|
23 n = size (A,1) ; |
|
24 |
|
25 figure (1) |
|
26 clf |
|
27 hold off |
|
28 subplot (2,1,1) ; |
|
29 % remove the "_" from the name before printing it in the plot title |
|
30 title (sprintf ('%s', strrep (Problem.name, '_', '-'))) ; |
|
31 fprintf ('Matrix name: %s\n', Problem.name) ; |
|
32 fprintf ('Matrix title: %s\n', Problem.title) ; |
|
33 spy (A) |
|
34 |
|
35 % print the details during AMD ordering and SYMBFACT |
|
36 control = amd (); |
|
37 control (3) = 1; |
|
38 |
|
39 % order the matrix. Note that the Info argument is optional. |
|
40 fprintf ('\nIf the next step fails, then you have\n') ; |
|
41 fprintf ('not yet compiled the AMD mexFunction.\n') ; |
|
42 [p, Info] = amd (A, control) ; |
|
43 |
|
44 % order again, but this time print some statistics |
|
45 [p, Info] = amd (A, [10 1 1]) ; |
|
46 |
|
47 fprintf ('Permutation vector:\n') ; |
|
48 fprintf (' %2d', p) ; |
|
49 fprintf ('\n\n') ; |
|
50 |
|
51 subplot (2,1,2) ; |
|
52 title ('Permuted matrix') ; |
|
53 spy (A (p,p)) |
|
54 |
|
55 % approximations from amd: |
|
56 lnz2 = n + Info (10) ; |
|
57 fl2 = n + Info (11) + 2 * Info (12) ; |
|
58 fprintf ('\nResults from AMD''s approximate analysis:\n') ; |
|
59 fprintf ('number of nonzeros in L (including diagonal): %d\n', lnz2) ; |
|
60 fprintf ('floating point operation count for chol (A (p,p)): %d\n\n', fl2) ; |
|
61 |