luDecompositionSolve static method

Matrix luDecompositionSolve(
  1. Matrix a,
  2. Matrix b
)

LU decomposition Doolittle method.

Example:

Matrix A = Matrix([
  [4, 1, -1],
  [1, 4, -1],
  [-1, -1, 4]
]);
Matrix b = Matrix([
  [6],
  [25],
  [14]
]);

Matrix result = LinearSystemSolvers.luDecompositionSolve(a, b);
print(result.round());
// Output:
// Matrix: 3x1
// ┌ 1 ┐
// │ 7 │
// └ 6 ┘

Implementation

static Matrix luDecompositionSolve(Matrix a, Matrix b) {
  a = _Utils.toNumMatrix(a);
  var lu = a.decomposition.luDecompositionDoolittle();
  Matrix l = lu.L;
  Matrix u = lu.U;

  // Solve Ly = b
  Matrix y = _Utils.forwardSubstitution(l, b);

  // Solve Ux = y
  Matrix x = _Utils.backwardSubstitution(u, y);

  return x;
}