Class LUDecomposition<F extends Field<F>>
- java.lang.Object
-
- org.jscience.mathematics.vector.LUDecomposition<F>
-
public final class LUDecomposition<F extends Field<F>> extends Object
This class represents the decomposition of a
matrix
A
into a product of alower
andupper
triangular matrices,L
andU
respectively, such asA = P·L·U
with
P
a
permutation
matrix.This decomposition is typically used to resolve linear systems of equations (Gaussian elimination) or to calculate the determinant of a square
Matrix
(O(m³)
).Numerical stability is guaranteed through pivoting if the
Field
elements arenumbers
For others elements types, numerical stability can be ensured by setting thecontext-local
pivot comparator (seesetPivotComparator(java.util.Comparator<org.jscience.mathematics.structure.Field>)
).Pivoting can be disabled by setting the
pivot comparator
tonull
(P
is then the matrix identity).- See Also:
- Wikipedia: LU decomposition
-
-
Field Summary
Fields
Modifier and Type
Field
Description
static Comparator<Field>
NUMERIC_COMPARATOR
Holds the default comparator for pivoting.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type
Method
Description
F
determinant()
Returns the determinant of the Matrix
having this
decomposition.
DenseMatrix<F>
getLower(F zero,
F one)
Returns the lower matrix decomposition (L
) with diagonal
elements equal to the multiplicative identity for F.
DenseMatrix<F>
getLU()
Returns the lower/upper decomposition in one single matrix.
SparseMatrix<F>
getPermutation(F zero,
F one)
Returns the permutation matrix (P
).
static Comparator<Field>
getPivotComparator()
Returns the local
comparator used for pivoting or null
if pivoting
is not performed (default NUMERIC_COMPARATOR
).
javolution.util.FastTable<javolution.util.Index>
getPivots()
Returns the pivots elements of this decomposition.
DenseMatrix<F>
getUpper(F zero)
Returns the upper matrix decomposition (U
).
DenseMatrix<F>
inverse()
Returns the solution X of the equation: A * X = Identity with
this = A.lu()
using back and forward substitutions.
static void
setPivotComparator(Comparator<Field> cmp)
Sets the local
comparator used
for pivoting or null
to disable pivoting.
DenseMatrix<F>
solve(Matrix<F> B)
Returns the solution X of the equation: A * X = B with
this = A.lu()
using back and forward substitutions.
static <F extends Field<F>>
LUDecomposition<F>
valueOf(Matrix<F> source)
Returns the lower/upper decomposition of the specified matrix.
-
-
Field Detail
-
NUMERIC_COMPARATOR
public static final Comparator<Field> NUMERIC_COMPARATOR
Holds the default comparator for pivoting.
-
Method Detail
-
valueOf
public static <F extends Field<F>> LUDecomposition<F> valueOf(Matrix<F> source)
Returns the lower/upper decomposition of the specified matrix.
- Parameters:
source
- the matrix for which the decomposition is calculated.
- Returns:
- the lower/upper decomposition of the specified matrix.
- Throws:
DimensionException
- if the specified matrix is not square.
-
setPivotComparator
public static void setPivotComparator(Comparator<Field> cmp)
Sets the local
comparator used
for pivoting or null
to disable pivoting.
- Parameters:
cmp
- the comparator for pivoting or null
.
-
getPivotComparator
public static Comparator<Field> getPivotComparator()
Returns the local
comparator used for pivoting or null
if pivoting
is not performed (default NUMERIC_COMPARATOR
).
- Returns:
- the comparator for pivoting or
null
.
-
solve
public DenseMatrix<F> solve(Matrix<F> B)
Returns the solution X of the equation: A * X = B with
this = A.lu()
using back and forward substitutions.
- Parameters:
B
- the input matrix.
- Returns:
- the solution X = (1 / A) * B.
- Throws:
DimensionException
- if the dimensions do not match.
-
inverse
public DenseMatrix<F> inverse()
Returns the solution X of the equation: A * X = Identity with
this = A.lu()
using back and forward substitutions.
- Returns:
this.solve(Identity)
-
determinant
public F determinant()
Returns the determinant of the Matrix
having this
decomposition.
- Returns:
- the determinant of the matrix source.
-
getLower
public DenseMatrix<F> getLower(F zero,
F one)
Returns the lower matrix decomposition (L
) with diagonal
elements equal to the multiplicative identity for F.
- Parameters:
zero
- the additive identity for F.
one
- the multiplicative identity for F.
- Returns:
- the lower matrix.
-
getUpper
public DenseMatrix<F> getUpper(F zero)
Returns the upper matrix decomposition (U
).
- Parameters:
zero
- the additive identity for F.
- Returns:
- the upper matrix.
-
getPermutation
public SparseMatrix<F> getPermutation(F zero,
F one)
Returns the permutation matrix (P
).
- Parameters:
zero
- the additive identity for F.
one
- the multiplicative identity for F.
- Returns:
- the permutation matrix.
-
getLU
public DenseMatrix<F> getLU()
Returns the lower/upper decomposition in one single matrix.
- Returns:
- the lower/upper matrix merged in a single matrix.
-
getPivots
public javolution.util.FastTable<javolution.util.Index> getPivots()
Returns the pivots elements of this decomposition.
- Returns:
- the row indices after permutation.