forwardSubstitution static method

List<double> forwardSubstitution(
  1. List<List<double>> source,
  2. List<double> vector
)

Forward substitution is an iterative process that solves equation matrices in the form Lx = b, where L is a lower triangular matrix.

In this case, source represents L and vector represents b.

Implementation

static List<double> forwardSubstitution(
  List<List<double>> source,
  List<double> vector,
) {
  final size = vector.length;
  final solutions = List<double>.generate(size, (_) => 0, growable: false);

  for (var i = 0; i < size; ++i) {
    solutions[i] = vector[i];
    for (var j = 0; j < i; ++j) {
      solutions[i] = solutions[i] - source[i][j] * solutions[j];
    }
    solutions[i] = solutions[i] / source[i][i];
  }

  return solutions;
}