GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
psinv.c
Go to the documentation of this file.
1 /* psinv.c CCMATH mathematics library source code.
2  *
3  * Copyright (C) 2000 Daniel A. Atkinson All rights reserved.
4  * This code may be redistributed under the terms of the GNU library
5  * public license (LGPL). ( See the lgpl.license file for details.)
6  * ------------------------------------------------------------------------
7  */
8 #include "ccmath.h"
9 int psinv(double *v, int n)
10 {
11  double z, *p, *q, *r, *s, *t;
12 
13  int j, k;
14 
15  for (j = 0, p = v; j < n; ++j, p += n + 1) {
16  for (q = v + j * n; q < p; ++q)
17  *p -= *q * *q;
18  if (*p <= 0.)
19  return -1;
20  *p = sqrt(*p);
21  for (k = j + 1, q = p + n; k < n; ++k, q += n) {
22  for (r = v + j * n, s = v + k * n, z = 0.; r < p;)
23  z += *r++ * *s++;
24  *q -= z;
25  *q /= *p;
26  }
27  }
28  trnm(v, n);
29  for (j = 0, p = v; j < n; ++j, p += n + 1) {
30  *p = 1. / *p;
31  for (q = v + j, t = v; q < p; t += n + 1, q += n) {
32  for (s = q, r = t, z = 0.; s < p; s += n)
33  z -= *s * *r++;
34  *q = z * *p;
35  }
36  }
37  for (j = 0, p = v; j < n; ++j, p += n + 1) {
38  for (q = v + j, t = p - j; q <= p; q += n) {
39  for (k = j, r = p, s = q, z = 0.; k < n; ++k)
40  z += *r++ * *s++;
41  *t++ = (*q = z);
42  }
43  }
44  return 0;
45 }
void trnm(double *a, int n)
Definition: trnm.c:8
int psinv(double *v, int n)
Definition: psinv.c:9
double t
Definition: r_raster.c:39
double r
Definition: r_raster.c:39