GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
psinv.c
Go to the documentation of this file.
00001 /*  psinv.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 "ccmath.h"
00009 int psinv(double *v, int n)
00010 {
00011     double z, *p, *q, *r, *s, *t;
00012 
00013     int j, k;
00014 
00015     for (j = 0, p = v; j < n; ++j, p += n + 1) {
00016         for (q = v + j * n; q < p; ++q)
00017             *p -= *q * *q;
00018         if (*p <= 0.)
00019             return -1;
00020         *p = sqrt(*p);
00021         for (k = j + 1, q = p + n; k < n; ++k, q += n) {
00022             for (r = v + j * n, s = v + k * n, z = 0.; r < p;)
00023                 z += *r++ * *s++;
00024             *q -= z;
00025             *q /= *p;
00026         }
00027     }
00028     trnm(v, n);
00029     for (j = 0, p = v; j < n; ++j, p += n + 1) {
00030         *p = 1. / *p;
00031         for (q = v + j, t = v; q < p; t += n + 1, q += n) {
00032             for (s = q, r = t, z = 0.; s < p; s += n)
00033                 z -= *s * *r++;
00034             *q = z * *p;
00035         }
00036     }
00037     for (j = 0, p = v; j < n; ++j, p += n + 1) {
00038         for (q = v + j, t = p - j; q <= p; q += n) {
00039             for (k = j, r = p, s = q, z = 0.; k < n; ++k)
00040                 z += *r++ * *s++;
00041             *t++ = (*q = z);
00042         }
00043     }
00044     return 0;
00045 }