51 static double *scales;
71 double pivot, biggest, mult, tempf;
81 scales =
N_NEW(n,
double);
83 for (i = 0; i < n; i++) {
86 for (j = 0; j < n; j++)
87 if (biggest < (tempf = fabs(lu[i][j] = a[i][j])))
90 scales[i] = 1.0 / biggest;
98 for (k = 0; k < n - 1; k++) {
101 for (i = k; i < n; i++) {
102 if (biggest < (tempf = fabs(lu[ps[i]][k]) * scales[ps[i]])) {
109 if (pivotindex != k) {
111 ps[k] = ps[pivotindex];
116 pivot = lu[ps[k]][k];
117 for (i = k + 1; i < n; i++) {
118 lu[ps[i]][k] = mult = lu[ps[i]][k] / pivot;
120 for (j = k + 1; j < n; j++)
121 lu[ps[i]][j] -= mult * lu[ps[k]][j];
126 if (lu[ps[n - 1]][n - 1] == 0.0)
148 for (i = 0; i < n; i++) {
150 for (j = 0; j < i; j++)
151 dot += lu[ps[i]][j] * x[j];
152 x[i] = b[ps[i]] -
dot;
156 for (i = n - 1; i >= 0; i--) {
158 for (j = i + 1; j < n; j++)
159 dot += lu[ps[i]][j] * x[j];
160 x[i] = (x[i] -
dot) / lu[ps[i]][i];
void free_array(double **rv)
double ** new_array(int i, int j, double val)
void lu_solve(double *x, double *b, int n)
int lu_decompose(double **a, int n)