GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
solvru.c
Go to the documentation of this file.
00001 /*  solvru.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 int solvru(double *a, double *b, int n)
00009 {
00010     int j, k;
00011 
00012     double fabs();
00013 
00014     double s, t, *p, *q;
00015 
00016     for (j = 0, s = 0., p = a; j < n; ++j, p += n + 1)
00017         if ((t = fabs(*p)) > s)
00018             s = t;
00019     s *= 1.e-16;
00020     for (j = n - 1, p = a + n * n - 1; j >= 0; --j, p -= n + 1) {
00021         for (k = j + 1, q = p + 1; k < n;)
00022             b[j] -= b[k++] * *q++;
00023         if (fabs(*p) < s)
00024             return -1;
00025         b[j] /= *p;
00026     }
00027     return 0;
00028 }