Package org.flag4j.linalg.solvers.exact
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:
LinearSolver<T,
U>
- Direct Known Subclasses:
ComplexExactSolver
,RealExactSolver
public abstract class ExactSolver<T extends MatrixMixin<T,?,?,?,?,?,U,?>,U extends VectorMixin<U,?,?,?,?,T,?,?>>
extends Object
implements LinearSolver<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
least-squares solver
.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final LinearSolver
<T, U> Backwards solver for solving system with upper triangular coefficient matrix.protected final LinearSolver
<T, U> Forward Solver for solving system with lower triangular coefficient matrix.Decomposer to computeLU
decomposition.protected T
The unit-lower and upper triangular matrices from theLU
decomposition stored in a single matrix.protected PermutationMatrix
Row permutation matrix forLU
decomposition. -
Constructor Summary
ModifierConstructorDescriptionprotected
ExactSolver
(LU<T> lu, LinearSolver<T, U> forwardSolver, LinearSolver<T, U> backSolver) Constructs an exact LU solver with a specifiedLU
decomposer. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Decomposes A using anLU decomposition
.protected abstract T
permuteRows
(T B) Permute the rows of a matrix using the row permutation matrix from the LU decomposition.protected abstract U
permuteRows
(U b) Permute the rows of a vector using the row permutation matrix from the LU decomposition.Solves the set of linear system of equations given byA*X=B
for the matrixX
.Solves the linear system of equations given byA*x=b
for the vectorx
.
-
Field Details
-
forwardSolver
protected final LinearSolver<T extends MatrixMixin<T,?, forwardSolver?, ?, ?, ?, U, ?>, U extends VectorMixin<U, ?, ?, ?, ?, T, ?, ?>> Forward Solver for solving system with lower triangular coefficient matrix. -
backSolver
protected final LinearSolver<T extends MatrixMixin<T,?, backSolver?, ?, ?, ?, U, ?>, U extends VectorMixin<U, ?, ?, ?, ?, T, ?, ?>> Backwards solver for solving system with upper triangular coefficient matrix. -
lu
Decomposer to computeLU
decomposition. -
LU
The unit-lower and upper triangular matrices from theLU
decomposition stored in a single matrix. -
rowPermute
Row permutation matrix forLU
decomposition.
-
-
Constructor Details
-
ExactSolver
Constructs an exact LU solver with a specifiedLU
decomposer.- Parameters:
lu
-LU
decomposer to employ in solving the linear system.- Throws:
IllegalArgumentException
- If theLU
decomposer does not use partial pivoting.
-
-
Method Details
-
decompose
Decomposes A using anLU decomposition
.- Parameters:
A
- Matrix to decompose.
-
solve
Solves the linear system of equations given byA*x=b
for the vectorx
. The system must be well determined.- Specified by:
solve
in interfaceLinearSolver<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 systemA*x=b
. - Throws:
IllegalArgumentException
- If the number of columns inA
is not equal to the number of entries inb
.IllegalArgumentException
- IfA
is not square.SingularMatrixException
- IfA
is singular.
-
solve
Solves the set of linear system of equations given byA*X=B
for the matrixX
.- Specified by:
solve
in interfaceLinearSolver<T extends MatrixMixin<T,
?, ?, ?, ?, ?, U, ?>, U extends VectorMixin<U, ?, ?, ?, ?, T, ?, ?>> - Parameters:
A
- Coefficient matrix in the linear system.B
- Matrix of constants in the linear system.- Returns:
- The solution to
X
in the linear systemA*X=B
. - Throws:
IllegalArgumentException
- If the number of columns inA
is not equal to the number of rows inB
.IllegalArgumentException
- IfA
is not square.SingularMatrixException
- IfA
is singular.
-
permuteRows
-
permuteRows
-