Class RealLU
Instances of this class can be used to compute the LU decomposition of a real dense matrix.
The LU decomposition decomposes a matrix \( A \) into the product of a unit-lower triangular matrix \( L \) and an upper triangular matrix \( U \), such that: \[ A = LU \]
Pivoting Strategies:
Pivoting may be used to improve the stability of the decomposition. Pivoting involves swapping rows and/or columns within the matrix during decomposition.
This class supports three pivoting strategies via the LU.Pivoting
enum:
LU.Pivoting.NONE
: No pivoting is performed. This pivoting strategy is generally not recommended. \[ A = LU \]LU.Pivoting.PARTIAL
: Only row pivoting is performed to improve numerical stability. Generally, this is the preferred pivoting strategy. The decomposition then becomes, \[ PA = LU \]
where \( P \) is a LU.Pivoting.FULL
: Both row and column pivoting are performed to enhance numerical robustness. The decomposition then becomes, \[ PAQ = LU \] where \( P \) and \( Q \) arepermutation matrices
representing the row and column swaps respectively.Full pivoting may be useful for highly ill-conditioned matrices but, for practical purposes, partial pivoting is generally sufficient and more performant.
permutation matrix
representing the row swaps.
Storage Format:
The computed LU decomposition is stored within a single matrixLU
, where:
- The upper triangular part (including the diagonal) represents the non-zero values of \( U \).
- The strictly lower triangular part represents the non-zero, non-diagonal values of \( L \). Since \( L \) is unit-lower triangular, the diagonal is not stored as it is known to be all zeros.
Usage:
The decomposition workflow typically follows these steps:- Instantiate an instance of
RealLU
. - Call
LU.decompose(MatrixMixin)
to perform the factorization. - Retrieve the resulting matrices using
getL()
,getU()
,LU.getP()
, andLU.getQ()
.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.flag4j.linalg.decompositions.lu.LU
LU.Pivoting
-
Field Summary
Fields inherited from class org.flag4j.linalg.decompositions.lu.LU
colSwaps, inPlace, LU, numColSwaps, numRowSwaps, P, pivotFlag, Q, rowSwaps, ZERO_PIV_ERR
Fields inherited from class org.flag4j.linalg.decompositions.Decomposition
hasDecomposed
-
Constructor Summary
ConstructorsModifierConstructorDescriptionRealLU()
Constructs a LU decomposer for real dense matrices.RealLU
(LU.Pivoting pivoting) Constructs a LU decomposer for real dense matrices.protected
RealLU
(LU.Pivoting pivoting, boolean inPlace) Constructs a LU decomposer for real dense matrices. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Computes the LU decomposition using full/rook pivoting (i.e. row and column swapping).getL()
Gets the unit lower triangular matrix of the decomposition.getU()
Gets the upper triangular matrix of the decomposition.protected void
noPivot()
Computes the LU decomposition using no pivoting (i.e. rows and columns are not swapped).protected void
Computes the LU decomposition using partial pivoting (i.e. row swapping).Methods inherited from class org.flag4j.linalg.decompositions.lu.LU
decompose, getLU, getNumColSwaps, getNumRowSwaps, getP, getQ, initLU, swapCols, swapRows
Methods inherited from class org.flag4j.linalg.decompositions.Decomposition
ensureHasDecomposed
-
Constructor Details
-
RealLU
public RealLU()Constructs a LU decomposer for real dense matrices.
This decomposition will be performed out-of-place using partial pivoting.
-
RealLU
Constructs a LU decomposer for real dense matrices.
This decomposition will be performed out-of-place.
- Parameters:
pivoting
- Pivoting to use. If pivoting is 2, full pivoting will be used. If pivoting is 1, partial pivoting will be used. If pivoting is any other value, no pivoting will be used.
-
RealLU
Constructs a LU decomposer for real dense matrices.- Parameters:
pivoting
- Pivoting to use.inPlace
- Flag indicating if the decomposition should be done in/out-of-place.- If
true
, then the decomposition will be done in-place. - If
true
, then the decomposition will be done out-of-place.
- If
-
-
Method Details
-
noPivot
-
partialPivot
protected void partialPivot()Computes the LU decomposition using partial pivoting (i.e. row swapping).- Specified by:
partialPivot
in classLU<Matrix>
-
fullPivot
-
getL
Gets the unit lower triangular matrix of the decomposition.- Specified by:
getL
in classLU<Matrix>
- Returns:
- The lower triangular matrix of the decomposition.
- Throws:
IllegalStateException
- If this method is called beforeinvalid reference
#decompose(Matrix)
-
getU
Gets the upper triangular matrix of the decomposition.- Specified by:
getU
in classLU<Matrix>
- Returns:
- The lower triangular matrix of the decomposition.
- Throws:
IllegalStateException
- If this method is called beforeinvalid reference
#decompose(Matrix)
-