atou1.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* atou1.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. void atou1(double *a, int m, int n)
  10. {
  11. double *p0, *p, *q, *w;
  12. int i, j, k, mm;
  13. double s, h;
  14. w = (double *)calloc(m, sizeof(double));
  15. p0 = a + n * n - 1;
  16. i = n - 1;
  17. mm = m - n;
  18. if (mm == 0) {
  19. *p0 = 1.;
  20. p0 -= n + 1;
  21. --i;
  22. ++mm;
  23. }
  24. for (; i >= 0; --i, ++mm, p0 -= n + 1) {
  25. if (*p0 != 0.) {
  26. for (j = 0, p = p0 + n; j < mm; p += n)
  27. w[j++] = *p;
  28. h = *p0;
  29. *p0 = 1. - h;
  30. for (j = 0, p = p0 + n; j < mm; p += n)
  31. *p = -h * w[j++];
  32. for (k = i + 1, q = p0 + 1; k < n; ++k) {
  33. for (j = 0, p = q + n, s = 0.; j < mm; p += n)
  34. s += w[j++] * *p;
  35. s *= h;
  36. for (j = 0, p = q + n; j < mm; p += n)
  37. *p -= s * w[j++];
  38. *q++ = -s;
  39. }
  40. }
  41. else {
  42. *p0 = 1.;
  43. for (j = 0, p = p0 + n, q = p0 + 1; j < mm; ++j, p += n)
  44. *p = *q++ = 0.;
  45. }
  46. }
  47. free(w);
  48. }