|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 /* ruinv.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 ruinv(double *a, int n) 00009 { 00010 int j; 00011 00012 double fabs(); 00013 00014 double tt, z, *p, *q, *r, *s, *t; 00015 00016 for (j = 0, tt = 0., p = a; j < n; ++j, p += n + 1) 00017 if ((z = fabs(*p)) > tt) 00018 tt = z; 00019 tt *= 1.e-16; 00020 for (j = 0, p = a; j < n; ++j, p += n + 1) { 00021 if (fabs(*p) < tt) 00022 return -1; 00023 *p = 1. / *p; 00024 for (q = a + j, t = a; q < p; t += n + 1, q += n) { 00025 for (s = q, r = t, z = 0.; s < p; s += n) 00026 z -= *s * *r++; 00027 *q = z * *p; 00028 } 00029 } 00030 return 0; 00031 }