26void solve(
double *a,
double *b,
double *c,
size_t n) {
30 const size_t nsq = n * n;
31 double *asave =
gv_calloc(nsq,
sizeof(
double));
32 double *csave =
gv_calloc(n,
sizeof(
double));
34 for (
size_t i = 0; i < n; i++)
36 for (
size_t i = 0; i < nsq; i++)
39 const size_t nm = n - 1;
40 for (
size_t i = 0; i < nm; i++) {
44 for (
size_t ii = i; ii < n; ii++) {
45 const double dum = fabs(a[ii * n + i]);
55 for (
size_t j = i; j < n; j++) {
56 const size_t t = istar * n + j;
57 swap(&a[t], &a[i * n + j]);
59 swap(&c[istar], &c[i]);
61 const size_t ip = i + 1;
62 for (
size_t ii = ip; ii < n; ii++) {
63 const double pivot = a[ii * n + i] / a[i * n + i];
64 c[ii] -= pivot * c[i];
65 for (
size_t j = 0; j < n; j++)
66 a[ii * n + j] = a[ii * n + j] - pivot * a[i * n + j];
70 if (fabs(a[n * n - 1]) < 1.e-10)
72 b[n - 1] = c[n - 1] / a[n * n - 1];
74 for (
size_t k = 0; k < nm; k++) {
75 const size_t m = n - k - 2;
77 const size_t mp = m + 1;
78 for (
size_t j = mp; j < n; j++)
79 b[m] -= a[m * n + j] * b[j];
83 for (
size_t i = 0; i < n; i++)
85 for (
size_t i = 0; i < nsq; i++)
91 printf(
"ill-conditioned\n");