/* simeq_lup.c */ /* solve for X, A X = Y, using L U = A decomposition */ #include #include #undef abs #define abs(x) (((x)<0.0)?(-(x)):(x)) void simeq_lup(int n, double A[], double Y[], double X[]) { double *B; /* [n][n+1] WORKING MATRIX */ int *ROW; /* ROW INTERCHANGE INDICIES */ double *by; /* interchanged Y */ int HOLD , I_PIVOT; /* PIVOT INDICIES */ double pivot; /* PIVOT ELEMENT VALUE */ int i, j, k, m, im, it; B = (double *)calloc(n*n, sizeof(double)); ROW = (int *)calloc(n, sizeof(int)); by = (double *)calloc(n, sizeof(double)); for(m=0; mpivot) { im = i; pivot = abs(A[ROW[i]*n+m]); } } it = ROW[im]; ROW[im] = ROW[m]; ROW[m] = it; } /* copy A into B with largest diagonal */ for(i=0; i=0; j--) { X[j] = by[j]; for(k=j+1; k