|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 /* hevmax.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 <stdlib.h> 00009 #include "ccmath.h" 00010 double hevmax(Cpx * a, Cpx * u, int n) 00011 { 00012 Cpx *x, *p, h; 00013 00014 double e, ep, s, t, te = 1.e-12; 00015 00016 int k, j; 00017 00018 x = (Cpx *) calloc(n, sizeof(Cpx)); 00019 x[0].re = 1.; 00020 e = 0.; 00021 do { 00022 for (k = 0, p = a, s = t = 0.; k < n; ++k) { 00023 for (j = 0, h.re = h.im = 0.; j < n; ++j, ++p) { 00024 h.re += p->re * x[j].re - p->im * x[j].im; 00025 h.im += p->im * x[j].re + p->re * x[j].im; 00026 } 00027 s += h.re * h.re + h.im * h.im; 00028 t += h.re * x[k].re + h.im * x[k].im; 00029 u[k] = h; 00030 } 00031 ep = e; 00032 e = s / t; 00033 s = 1. / sqrt(s); 00034 for (k = 0; k < n; ++k) { 00035 u[k].re *= s; 00036 u[k].im *= s; 00037 x[k] = u[k]; 00038 } 00039 } while (fabs(e - ep) > fabs(te * e)); 00040 free(x); 00041 return e; 00042 }