13 void lubksb(float **a, int n, int *indx, float b[])
14 // Solves the set of n linear equations A.X=B. Here a[n][n] is input, not as the matrix
15 // A but rather as its LU decomposition determined by the routine ludcmp. indx[n] is input
16 // as the permutation vector returned by ludcmp. b[n] is input as the right-hand side vector
17 // B, and returns with the solution vector X. a, n and indx are not modified by this routine
18 // and can be left in place for successive calls with different right-hand sides b. This routine takes
19 // into account the possibility that b will begin with many zero elements, so it is efficient for use
20 // in matrix inversion
30 for (j=ii;j<i;j++) sum -= a[i][j]*b[j];
34 for (i=n-1;i>=0;i--) {
36 for (j=i+1;j<n;j++) sum -= a[i][j]*b[j];
40 /* (C) Copr. 1986-92 Numerical Recipes Software */
43 int ludcmp(float **a, int n, int *indx, float *d)
44 // given a matrix a[n][n] this routine replaces it with the LU decomposition of a rowwise
45 // permutation of itself. a and n are input. a is output, arranged as in above equation;
46 // indx[n] is an output vector that records the row permutation effected by the partial
47 // pivoting; d is output as +/-1 depending on whether the number of row interchanges was even
48 // or odd, respectively. This routine is used in combination with lubksb to solve linear
49 // equations or invert a matrix.
52 float big,dum,sum,temp;
56 vv=(float*)malloc(sizeof(float)*n);
61 if ((temp=(float)fabs(a[i][j])) > big) big=temp;
62 if (big == 0.0) return 1;
68 for (k=0;k<i;k++) sum -= a[i][k]*a[k][j];
75 sum -= a[i][k]*a[k][j];
77 if ( (dum=vv[i]*(float)fabs(sum)) >= big) {
92 if (a[j][j] == 0.0) a[j][j]=TINY;
95 for (i=j+1;i<n;i++) a[i][j] *= dum;
101 /* (C) Copr. 1986-92 Numerical Recipes Software */