GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
hevmax.c
Go to the documentation of this file.
1 /* hevmax.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 <stdlib.h>
9 #include "ccmath.h"
10 double hevmax(Cpx * a, Cpx * u, int n)
11 {
12  Cpx *x, *p, h;
13 
14  double e, ep, s, t, te = 1.e-12;
15 
16  int k, j;
17 
18  x = (Cpx *) calloc(n, sizeof(Cpx));
19  x[0].re = 1.;
20  e = 0.;
21  do {
22  for (k = 0, p = a, s = t = 0.; k < n; ++k) {
23  for (j = 0, h.re = h.im = 0.; j < n; ++j, ++p) {
24  h.re += p->re * x[j].re - p->im * x[j].im;
25  h.im += p->im * x[j].re + p->re * x[j].im;
26  }
27  s += h.re * h.re + h.im * h.im;
28  t += h.re * x[k].re + h.im * x[k].im;
29  u[k] = h;
30  }
31  ep = e;
32  e = s / t;
33  s = 1. / sqrt(s);
34  for (k = 0; k < n; ++k) {
35  u[k].re *= s;
36  u[k].im *= s;
37  x[k] = u[k];
38  }
39  } while (fabs(e - ep) > fabs(te * e));
40  free(x);
41  return e;
42 }
void free(void *)
#define x
double t
Definition: r_raster.c:39
double re
Definition: ccmath.h:38
double hevmax(Cpx *a, Cpx *u, int n)
Definition: hevmax.c:10
double im
Definition: ccmath.h:38
Definition: la.h:54