Package org.apache.commons.math3.linear
Class LUDecomposition
java.lang.Object
org.apache.commons.math3.linear.LUDecomposition
Calculates the LUP-decomposition of a square matrix.
The LUP-decomposition of a matrix A consists of three matrices L, U and P that satisfy: P×A = L×U. L is lower triangular (with unit diagonal terms), U is upper triangular and P is a permutation matrix. All matrices are m×m.
As shown by the presence of the P matrix, this decomposition is implemented using partial pivoting.
This class is based on the class with similar name from the JAMA library.
- a
getP
method has been added, - the
det
method has been renamed asgetDeterminant
, - the
getDoublePivot
method has been removed (but the int basedgetPivot
method has been kept), - the
solve
andisNonSingular
methods have been replaced by agetSolver
method and the equivalent methods provided by the returnedDecompositionSolver
.
- Since:
- 2.0 (changed to concrete class in 3.0)
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate RealMatrix
Cached value of L.private RealMatrix
Cached value of P.private RealMatrix
Cached value of U.private static final double
Default bound to determine effective singularity in LU decomposition.private boolean
Parity of the permutation associated with the LU decomposition.private final double[][]
Entries of LU decomposition.private final int[]
Pivot permutation associated with LU decomposition.private boolean
Singularity indicator. -
Constructor Summary
ConstructorsConstructorDescriptionLUDecomposition
(RealMatrix matrix) Calculates the LU-decomposition of the given matrix.LUDecomposition
(RealMatrix matrix, double singularityThreshold) Calculates the LU-decomposition of the given matrix. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Return the determinant of the matrixgetL()
Returns the matrix L of the decomposition.getP()
Returns the P rows permutation matrix.int[]
getPivot()
Returns the pivot permutation vector.Get a solver for finding the A × X = B solution in exact linear sense.getU()
Returns the matrix U of the decomposition.
-
Field Details
-
DEFAULT_TOO_SMALL
private static final double DEFAULT_TOO_SMALLDefault bound to determine effective singularity in LU decomposition.- See Also:
-
lu
private final double[][] luEntries of LU decomposition. -
pivot
private final int[] pivotPivot permutation associated with LU decomposition. -
even
private boolean evenParity of the permutation associated with the LU decomposition. -
singular
private boolean singularSingularity indicator. -
cachedL
Cached value of L. -
cachedU
Cached value of U. -
cachedP
Cached value of P.
-
-
Constructor Details
-
LUDecomposition
Calculates the LU-decomposition of the given matrix. This constructor uses 1e-11 as default value for the singularity threshold.- Parameters:
matrix
- Matrix to decompose.- Throws:
NonSquareMatrixException
- if matrix is not square.
-
LUDecomposition
Calculates the LU-decomposition of the given matrix.- Parameters:
matrix
- The matrix to decompose.singularityThreshold
- threshold (based on partial row norm) under which a matrix is considered singular- Throws:
NonSquareMatrixException
- if matrix is not square
-
-
Method Details
-
getL
Returns the matrix L of the decomposition.L is a lower-triangular matrix
- Returns:
- the L matrix (or null if decomposed matrix is singular)
-
getU
Returns the matrix U of the decomposition.U is an upper-triangular matrix
- Returns:
- the U matrix (or null if decomposed matrix is singular)
-
getP
Returns the P rows permutation matrix.P is a sparse matrix with exactly one element set to 1.0 in each row and each column, all other elements being set to 0.0.
The positions of the 1 elements are given by the
pivot permutation vector
.- Returns:
- the P rows permutation matrix (or null if decomposed matrix is singular)
- See Also:
-
getPivot
public int[] getPivot()Returns the pivot permutation vector.- Returns:
- the pivot permutation vector
- See Also:
-
getDeterminant
public double getDeterminant()Return the determinant of the matrix- Returns:
- determinant of the matrix
-
getSolver
Get a solver for finding the A × X = B solution in exact linear sense.- Returns:
- a solver
-