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

« back to all changes in this revision

Viewing changes to LDL/Demo/ldllsimple.c

  • 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
/* ========================================================================== */
 
2
/* === ldllsimple.c:  a simple LDL main program (long integer version) ====== */
 
3
/* ========================================================================== */
 
4
 
 
5
/* LDLSIMPLE:  this is a very simple main program that illustrates the basic
 
6
 * usage of the LDL routines.  The output of this program is in ldlsimple.out.
 
7
 * This program factorizes the matrix
 
8
 *
 
9
 *    A =[ ...
 
10
 *    1.7     0     0     0     0     0     0     0   .13     0
 
11
 *      0    1.     0     0   .02     0     0     0     0   .01
 
12
 *      0     0   1.5     0     0     0     0     0     0     0
 
13
 *      0     0     0   1.1     0     0     0     0     0     0
 
14
 *      0   .02     0     0   2.6     0   .16   .09   .52   .53
 
15
 *      0     0     0     0     0   1.2     0     0     0     0
 
16
 *      0     0     0     0   .16     0   1.3     0     0   .56
 
17
 *      0     0     0     0   .09     0     0   1.6   .11     0
 
18
 *    .13     0     0     0   .52     0     0   .11   1.4     0
 
19
 *      0   .01     0     0   .53     0   .56     0     0   3.1 ] ;
 
20
 *
 
21
 * and then solves a system Ax=b whose true solution is
 
22
 * x = [.1 .2 .3 .4 .5 .6 .7 .8 .9 1]' ;
 
23
 *
 
24
 * Note that Li and Lx are statically allocated, with length 13.  This is just
 
25
 * enough to hold the factor L, but normally this size is not known until after
 
26
 * ldl_symbolic has analyzed the matrix.  The size of Li and Lx must be greater
 
27
 * than or equal to lnz = Lp [N], which is 13 for this matrix L.
 
28
 *
 
29
 * LDL Version 1.3, Copyright (c) 2006 by Timothy A Davis,
 
30
 * University of Florida.  All Rights Reserved.  See README for the License.
 
31
 */
 
32
 
 
33
#ifndef LDL_LONG
 
34
#define LDL_LONG
 
35
#endif
 
36
 
 
37
#include <stdio.h>
 
38
#include "ldl.h"
 
39
#define N 10    /* A is 10-by-10 */
 
40
#define ANZ 19  /* # of nonzeros on diagonal and upper triangular part of A */
 
41
#define LNZ 13  /* # of nonzeros below the diagonal of L */
 
42
 
 
43
int main (void)
 
44
{
 
45
    /* only the upper triangular part of A is required */
 
46
    UF_long Ap[N+1] = {0, 1, 2, 3, 4,   6, 7,   9,   11,      15,     ANZ},
 
47
           Ai [ANZ] = {0, 1, 2, 3, 1,4, 5, 4,6, 4,7, 0,4,7,8, 1,4,6,9 } ;
 
48
    double Ax [ANZ] = {1.7, 1., 1.5, 1.1, .02,2.6, 1.2, .16,1.3, .09,1.6,
 
49
                     .13,.52,.11,1.4, .01,.53,.56,3.1},
 
50
           b [N] = {.287, .22, .45, .44, 2.486, .72, 1.55, 1.424, 1.621, 3.759};
 
51
    double Lx [LNZ], D [N], Y [N] ;
 
52
    UF_long Li [LNZ], Lp [N+1], Parent [N], Lnz [N], Flag [N], Pattern [N], d, i ;
 
53
 
 
54
    /* factorize A into LDL' (P and Pinv not used) */
 
55
    ldl_l_symbolic (N, Ap, Ai, Lp, Parent, Lnz, Flag, NULL, NULL) ;
 
56
    printf ("Nonzeros in L, excluding diagonal: %d\n", Lp [N]) ;
 
57
    d = ldl_l_numeric (N, Ap, Ai, Ax, Lp, Parent, Lnz, Li, Lx, D, Y, Pattern,
 
58
        Flag, NULL, NULL) ;
 
59
 
 
60
    if (d == N)
 
61
    {
 
62
        /* solve Ax=b, overwriting b with the solution x */
 
63
        ldl_l_lsolve (N, b, Lp, Li, Lx) ;
 
64
        ldl_l_dsolve (N, b, D) ;
 
65
        ldl_l_ltsolve (N, b, Lp, Li, Lx) ;
 
66
        for (i = 0 ; i < N ; i++) printf ("x [%d] = %g\n", i, b [i]) ;
 
67
    }
 
68
    else
 
69
    {
 
70
        printf ("ldl_l_numeric failed, D (%d,%d) is zero\n", d, d) ;
 
71
    }
 
72
    return (0) ;
 
73
}