hevmax.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. double e, ep, s, t, te = 1.e-12;
  14. int k, j;
  15. x = (Cpx *) calloc(n, sizeof(Cpx));
  16. x[0].re = 1.;
  17. e = 0.;
  18. do {
  19. for (k = 0, p = a, s = t = 0.; k < n; ++k) {
  20. for (j = 0, h.re = h.im = 0.; j < n; ++j, ++p) {
  21. h.re += p->re * x[j].re - p->im * x[j].im;
  22. h.im += p->im * x[j].re + p->re * x[j].im;
  23. }
  24. s += h.re * h.re + h.im * h.im;
  25. t += h.re * x[k].re + h.im * x[k].im;
  26. u[k] = h;
  27. }
  28. ep = e;
  29. e = s / t;
  30. s = 1. / sqrt(s);
  31. for (k = 0; k < n; ++k) {
  32. u[k].re *= s;
  33. u[k].im *= s;
  34. x[k] = u[k];
  35. }
  36. } while (fabs(e - ep) > fabs(te * e));
  37. free(x);
  38. return e;
  39. }