solvru.c 759 B

1234567891011121314151617181920212223242526272829
  1. /* solvru.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. int solvru(double *a, double *b, int n)
  9. {
  10. int j, k;
  11. double fabs();
  12. double s, t, *p, *q;
  13. for (j = 0, s = 0., p = a; j < n; ++j, p += n + 1)
  14. if ((t = fabs(*p)) > s)
  15. s = t;
  16. s *= 1.e-16;
  17. for (j = n - 1, p = a + n * n - 1; j >= 0; --j, p -= n + 1) {
  18. for (k = j + 1, q = p + 1; k < n;)
  19. b[j] -= b[k++] * *q++;
  20. if (fabs(*p) < s)
  21. return -1;
  22. b[j] /= *p;
  23. }
  24. return 0;
  25. }