public static Matrix SubsBack(Matrix A, Matrix b) // Function solves Ax = b for A as an upper triangular matrix { if (A.L == null) { A.MakeLU(); } int n = A.rows; Matrix x = new Matrix(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 Matrix SubsForth(Matrix A, Matrix b) // Function solves Ax = b for A as a lower triangular matrix { if (A.L == null) { A.MakeLU(); } int n = A.rows; Matrix x = new Matrix(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); }
public static Matrix SubsBack(Matrix A, Matrix b) // Function solves Ax = b for A as an upper triangular matrix { if (A.L == null) A.MakeLU(); int n = A.rows; Matrix x = new Matrix(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 Matrix SubsForth(Matrix A, Matrix b) // Function solves Ax = b for A as a lower triangular matrix { if (A.L == null) A.MakeLU(); int n = A.rows; Matrix x = new Matrix(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; }