~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to KLU/Demo/kludemo.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 x = kludemo (A, b)
2
 
% x = kludemo (A, b)
3
 
%
4
 
% Writes out the matrix A as a file, calls the
5
 
% stand-alone kludemo program, and reads the
6
 
% solution back in.  If b is not provided, it
7
 
% is constructed as b = A*xtrue where
8
 
% xtrue = 1 + (0:n-1) / n.
9
 
 
10
 
[m n] = size (A) ;
11
 
if (m ~= n)
12
 
    error ('A must be square') ;
13
 
end
14
 
 
15
 
% create the files for the matrix A
16
 
[Ai j Ax] = find (A) ;
17
 
Ap = cumsum ([1 (sum (spones (A)))]) ;
18
 
Ai = Ai - 1 ;
19
 
Ap = Ap - 1 ;
20
 
 
21
 
f = fopen ('tmp/Asize', 'w') ;
22
 
fprintf (f, '%d %d %d\n', n, n, nnz (A)) ;
23
 
fclose (f) ;
24
 
 
25
 
f = fopen ('tmp/Ap', 'w') ;
26
 
fprintf (f, '%d\n', Ap) ;
27
 
fclose (f) ;
28
 
 
29
 
f = fopen ('tmp/Ai', 'w') ;
30
 
fprintf (f, '%d\n', Ai) ;
31
 
fclose (f) ;
32
 
 
33
 
f = fopen ('tmp/Ax', 'w') ;
34
 
fprintf (f, '%24.16e\n', Ax) ;
35
 
fclose (f) ;
36
 
 
37
 
if (nargin > 1)
38
 
    f = fopen ('tmp/b', 'w') ;
39
 
    fprintf (f, '%24.16e\n', b) ;
40
 
    fclose (f) ;
41
 
else
42
 
    if (exist ('tmp/b', 'file'))
43
 
        delete ('tmp/b') ;
44
 
    end
45
 
end
46
 
 
47
 
% solve Ax=b 
48
 
! ./kludemo > o
49
 
 
50
 
% get the solution
51
 
x = load ('tmp/x') ;
52