public static LUDecompositionCommons SubsBack(LUDecompositionCommons A, LUDecompositionCommons b) // Function solves Ax = b for A as an upper triangular LUDecompositionCommons { if (A.L == null) { A.MakeLU(); } int n = A.rows; LUDecompositionCommons x = new LUDecompositionCommons(n, 1); for (int i = n - 1; i > -1; i--) { x[i, 0] = b[i, 0]; for (int j = n - 1; j > i; j--) { x[i, 0] -= A[i, j] * x[j, 0]; } x[i, 0] = x[i, 0] / A[i, i]; } return(x); }
public static LUDecompositionCommons SubsForth(LUDecompositionCommons A, LUDecompositionCommons b) // Function solves Ax = b for A as a lower triangular LUDecompositionCommons { if (A.L == null) { A.MakeLU(); } int n = A.rows; LUDecompositionCommons x = new LUDecompositionCommons(n, 1); for (int i = 0; i < n; i++) { x[i, 0] = b[i, 0]; for (int j = 0; j < i; j++) { x[i, 0] -= A[i, j] * x[j, 0]; } x[i, 0] = x[i, 0] / A[i, i]; } return(x); }