ruinv.c 821 B

1234567891011121314151617181920212223242526272829303132
  1. /* ruinv.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 ruinv(double *a, int n)
  9. {
  10. int j;
  11. double fabs();
  12. double tt, z, *p, *q, *r, *s, *t;
  13. for (j = 0, tt = 0., p = a; j < n; ++j, p += n + 1)
  14. if ((z = fabs(*p)) > tt)
  15. tt = z;
  16. tt *= 1.e-16;
  17. for (j = 0, p = a; j < n; ++j, p += n + 1) {
  18. if (fabs(*p) < tt)
  19. return -1;
  20. *p = 1. / *p;
  21. for (q = a + j, t = a; q < p; t += n + 1, q += n) {
  22. for (s = q, r = t, z = 0.; s < p; s += n)
  23. z -= *s * *r++;
  24. *q = z * *p;
  25. }
  26. }
  27. return 0;
  28. }