ortho.c 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* ortho.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. static double tpi = 6.28318530717958647;
  10. void ortho(double *e, int n)
  11. {
  12. int i, j, k, m;
  13. double *p, *q, c, s, a, unfl();
  14. for (i = 0, p = e; i < n; ++i) {
  15. for (j = 0; j < n; ++j) {
  16. if (i == j)
  17. *p++ = 1.;
  18. else
  19. *p++ = 0.;
  20. }
  21. }
  22. for (i = 0, m = n - 1; i < m; ++i) {
  23. for (j = i + 1; j < n; ++j) {
  24. a = tpi * unfl();
  25. c = cos(a);
  26. s = sin(a);
  27. p = e + n * i;
  28. q = e + n * j;
  29. for (k = 0; k < n; ++k) {
  30. a = *p * c + *q * s;
  31. *q = *q * c - *p * s;
  32. *p++ = a;
  33. ++q;
  34. }
  35. }
  36. }
  37. }