Class ExactSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>>

java.lang.Object
org.flag4j.linalg.solvers.exact.ExactSolver<T,U>
All Implemented Interfaces:
LinearMatrixSolver<T,U>, LinearSolver<T>
Direct Known Subclasses:
ComplexExactSolver, RealExactSolver

public abstract class ExactSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>> extends Object implements LinearMatrixSolver<T,U>

Solves a well determined system of equations Ax=b in an exact sense by using a LU decomposition.

If the system is not well determined, i.e. A is square and full rank, then use a

invalid reference
least-squares solver
.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final LinearMatrixSolver<T,U>
    Backwards solver for solving system with upper triangular coefficient matrix.
    protected final LinearMatrixSolver<T,U>
    Forward Solver for solving system with lower triangular coefficient matrix.
    protected final LU<T>
    Decomposer to compute LU decomposition.
    protected T
    The unit-lower and upper triangular matrices from the LU decomposition stored in a single matrix.
    Row permutation matrix for LU decomposition.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ExactSolver(LU<T> lu, LinearMatrixSolver<T,U> forwardSolver, LinearMatrixSolver<T,U> backSolver)
    Constructs an exact LU solver with a specified LU decomposer.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Decomposes A using an LU decomposition.
    protected abstract T
    Permute the rows of a matrix using the row permutation matrix from the LU decomposition.
    protected abstract U
    Permute the rows of a vector using the row permutation matrix from the LU decomposition.
    solve(T A, T B)
    Solves the set of linear system of equations given by A*X=B for the matrix X.
    solve(T A, U b)
    Solves the linear system of equations given by A*x=b for the vector x.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • forwardSolver

      protected final LinearMatrixSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>> forwardSolver
      Forward Solver for solving system with lower triangular coefficient matrix.
    • backSolver

      protected final LinearMatrixSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>> backSolver
      Backwards solver for solving system with upper triangular coefficient matrix.
    • lu

      protected final LU<T extends MatrixMixin<T,?,U,?>> lu
      Decomposer to compute LU decomposition.
    • LU

      protected T extends MatrixMixin<T,?,U,?> LU
      The unit-lower and upper triangular matrices from the LU decomposition stored in a single matrix.
    • rowPermute

      protected PermutationMatrix rowPermute
      Row permutation matrix for LU decomposition.
  • Constructor Details

    • ExactSolver

      protected ExactSolver(LU<T> lu, LinearMatrixSolver<T,U> forwardSolver, LinearMatrixSolver<T,U> backSolver)
      Constructs an exact LU solver with a specified LU decomposer.
      Parameters:
      lu - LU decomposer to employ in solving the linear system.
      Throws:
      IllegalArgumentException - If the LU decomposer does not use partial pivoting.
  • Method Details

    • decompose

      protected void decompose(T A)
      Decomposes A using an LU decomposition.
      Parameters:
      A - Matrix to decompose.
    • solve

      public U solve(T A, U b)
      Solves the linear system of equations given by A*x=b for the vector x. The system must be well determined.
      Specified by:
      solve in interface LinearMatrixSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>>
      Parameters:
      A - Coefficient matrix in the linear system. Must be square and have full rank (i.e. all rows, or equivalently columns, must be linearly independent).
      b - Vector of constants in the linear system.
      Returns:
      The solution to x in the linear system A*x=b.
      Throws:
      IllegalArgumentException - If the number of columns in A is not equal to the number of data in b.
      IllegalArgumentException - If A is not square.
      SingularMatrixException - If A is singular.
    • solve

      public T solve(T A, T B)
      Solves the set of linear system of equations given by A*X=B for the matrix X.
      Specified by:
      solve in interface LinearMatrixSolver<T extends MatrixMixin<T,?,U,?>,U extends VectorMixin<U,T,?,?>>
      Specified by:
      solve in interface LinearSolver<T extends MatrixMixin<T,?,U,?>>
      Parameters:
      A - Coefficient matrix in the linear system.
      B - Matrix of constants in the linear system.
      Returns:
      The solution to X in the linear system A*X=B.
      Throws:
      IllegalArgumentException - If the number of columns in A is not equal to the number of rows in B.
      IllegalArgumentException - If A is not square.
      SingularMatrixException - If A is singular.
    • permuteRows

      protected abstract U permuteRows(U b)
      Permute the rows of a vector using the row permutation matrix from the LU decomposition.
      Parameters:
      b - Vector to permute the rows of.
      Returns:
      A vector which is the result of applying the row permutation from the LU decomposition to the vector b.
    • permuteRows

      protected abstract T permuteRows(T B)
      Permute the rows of a matrix using the row permutation matrix from the LU decomposition.
      Parameters:
      B - matrix to permute the rows of.
      Returns:
      A matrix which is the result of applying the row permutation from the LU decomposition to the matrix B.