|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 /* solvps.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 solvps(double *a, double *b, int n) 00010 { 00011 double *p, *q, *r, *s, t; 00012 00013 int j, k; 00014 00015 for (j = 0, p = a; j < n; ++j, p += n + 1) { 00016 for (q = a + 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 = a + j * n, s = a + k * n, t = 0.; r < p;) 00023 t += *r++ * *s++; 00024 *q -= t; 00025 *q /= *p; 00026 } 00027 } 00028 for (j = 0, p = a; j < n; ++j, p += n + 1) { 00029 for (k = 0, q = a + j * n; k < j;) 00030 b[j] -= b[k++] * *q++; 00031 b[j] /= *p; 00032 } 00033 for (j = n - 1, p = a + n * n - 1; j >= 0; --j, p -= n + 1) { 00034 for (k = j + 1, q = p + n; k < n; q += n) 00035 b[j] -= b[k++] * *q; 00036 b[j] /= *p; 00037 } 00038 return 0; 00039 }