/** * LU Decomposition Back Solve; this method takes the LU matrix and the permutation vector * produced by the GMatrix method LUD and solves the equation (LU)*x = b by placing the solution * vector x into this vector. This vector should be the same length or longer than b. * * @param LU The matrix into which the lower and upper decompostions have been placed * @param b The b vector in the equation (LU)*x = b * @param permutation The row permuations that were necessary to produce the LU matrix parameter */ public final void LUDBackSolve(GMatrix LU, GVector b, GVector permutation) { int size = LU.nRow * LU.nCol; double[] temp = new double[size]; double[] result = new double[size]; int[] row_perm = new int[b.getSize()]; int i, j; if (LU.nRow != b.getSize()) { throw new MismatchedSizeException(VecMathI18N.getString("GVector16")); } if (LU.nRow != permutation.getSize()) { throw new MismatchedSizeException(VecMathI18N.getString("GVector24")); } if (LU.nRow != LU.nCol) { throw new MismatchedSizeException(VecMathI18N.getString("GVector25")); } for (i = 0; i < LU.nRow; i++) { for (j = 0; j < LU.nCol; j++) { temp[i * LU.nCol + j] = LU.values[i][j]; } } for (i = 0; i < size; i++) result[i] = 0.0; for (i = 0; i < LU.nRow; i++) result[i * LU.nCol] = b.values[i]; for (i = 0; i < LU.nCol; i++) row_perm[i] = (int) permutation.values[i]; GMatrix.luBacksubstitution(LU.nRow, temp, row_perm, result); for (i = 0; i < LU.nRow; i++) this.values[i] = result[i * LU.nCol]; }