GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
ldumat.c
Go to the documentation of this file.
00001 /*  ldumat.c    CCMATH mathematics library source code.
00002  *
00003  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
00004  *  This code may be redistributed under the terms of the GNU library
00005  *  public license (LGPL). ( See the lgpl.license file for details.)
00006  * ------------------------------------------------------------------------
00007  */
00008 #include <stdlib.h>
00009 void ldumat(double *a, double *u, int m, int n)
00010 {
00011     double *p0, *q0, *p, *q, *w;
00012 
00013     int i, j, k, mm;
00014 
00015     double s, h;
00016 
00017     w = (double *)calloc(m, sizeof(double));
00018     for (i = 0, mm = m * m, q = u; i < mm; ++i)
00019         *q++ = 0.;
00020     p0 = a + n * n - 1;
00021     q0 = u + m * m - 1;
00022     mm = m - n;
00023     i = n - 1;
00024     for (j = 0; j < mm; ++j, q0 -= m + 1)
00025         *q0 = 1.;
00026     if (mm == 0) {
00027         p0 -= n + 1;
00028         *q0 = 1.;
00029         q0 -= m + 1;
00030         --i;
00031         ++mm;
00032     }
00033     for (; i >= 0; --i, ++mm, p0 -= n + 1, q0 -= m + 1) {
00034         if (*p0 != 0.) {
00035             for (j = 0, p = p0 + n, h = 1.; j < mm; p += n)
00036                 w[j++] = *p;
00037             h = *p0;
00038             *q0 = 1. - h;
00039             for (j = 0, q = q0 + m; j < mm; q += m)
00040                 *q = -h * w[j++];
00041             for (k = i + 1, q = q0 + 1; k < m; ++k) {
00042                 for (j = 0, p = q + m, s = 0.; j < mm; p += m)
00043                     s += w[j++] * *p;
00044                 s *= h;
00045                 for (j = 0, p = q + m; j < mm; p += m)
00046                     *p -= s * w[j++];
00047                 *q++ = -s;
00048             }
00049         }
00050         else {
00051             *q0 = 1.;
00052             for (j = 0, p = q0 + 1, q = q0 + m; j < mm; ++j, q += m)
00053                 *q = *p++ = 0.;
00054         }
00055     }
00056     free(w);
00057 }