Top Description Inners Fields Constructors Methods
org.apache.commons.math3.linear

public Class LUDecomposition

extends Object
Class Inheritance
Imports
org.apache.commons.math3.exception.DimensionMismatchException, org.apache.commons.math3.util.FastMath

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.

Since
2.0 (changed to concrete class in 3.0)
See Also
MathWorld, Wikipedia

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LUDecomposition.Solver

Specialized solver.

Field Summary

Modifier and TypeField and Description
private RealMatrix
cachedL

Cached value of L.

private RealMatrix
cachedP

Cached value of P.

private RealMatrix
cachedU

Cached value of U.

private static final double
DEFAULT_TOO_SMALL

Default bound to determine effective singularity in LU decomposition.

private boolean
even

Parity of the permutation associated with the LU decomposition.

private final double[][]
lu

Entries of LU decomposition.

private final int[]
pivot

Pivot permutation associated with LU decomposition.

private boolean
singular

Singularity indicator.

Constructor Summary

AccessConstructor and Description
public
LUDecomposition(RealMatrix
Matrix to decompose.
matrix
)

Calculates the LU-decomposition of the given matrix.

public
LUDecomposition(RealMatrix
The matrix to decompose.
matrix
,
double
threshold (based on partial row norm) under which a matrix is considered singular
singularityThreshold
)

Calculates the LU-decomposition of the given matrix.

Method Summary

Modifier and TypeMethod and Description
public double

Returns:

determinant of the matrix
getDeterminant
()

Return the determinant of the matrix

public RealMatrix

Returns:

the L matrix (or null if decomposed matrix is singular)
getL
()

Returns the matrix L of the decomposition.

public RealMatrix

Returns:

the P rows permutation matrix (or null if decomposed matrix is singular)
getP
()

Returns the P rows permutation matrix.

public int[]

Returns:

the pivot permutation vector
getPivot
()

Returns the pivot permutation vector.

public DecompositionSolver

Returns:

a solver
getSolver
()

Get a solver for finding the A × X = B solution in exact linear sense.

public RealMatrix

Returns:

the U matrix (or null if decomposed matrix is singular)
getU
()

Returns the matrix U of the decomposition.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedLback to summary
private RealMatrix cachedL

Cached value of L.

cachedPback to summary
private RealMatrix cachedP

Cached value of P.

cachedUback to summary
private RealMatrix cachedU

Cached value of U.

DEFAULT_TOO_SMALLback to summary
private static final double DEFAULT_TOO_SMALL

Default bound to determine effective singularity in LU decomposition.

evenback to summary
private boolean even

Parity of the permutation associated with the LU decomposition.

luback to summary
private final double[][] lu

Entries of LU decomposition.

pivotback to summary
private final int[] pivot

Pivot permutation associated with LU decomposition.

singularback to summary
private boolean singular

Singularity indicator.

Constructor Detail

LUDecompositionback to summary
public LUDecomposition(RealMatrix matrix)

Calculates the LU-decomposition of the given matrix. This constructor uses 1e-11 as default value for the singularity threshold.

Parameters
matrix:RealMatrix

Matrix to decompose.

Exceptions
NonSquareMatrixException:
if matrix is not square.
LUDecompositionback to summary
public LUDecomposition(RealMatrix matrix, double singularityThreshold)

Calculates the LU-decomposition of the given matrix.

Parameters
matrix:RealMatrix

The matrix to decompose.

singularityThreshold:double

threshold (based on partial row norm) under which a matrix is considered singular

Exceptions
NonSquareMatrixException:
if matrix is not square

Method Detail

getDeterminantback to summary
public double getDeterminant()

Return the determinant of the matrix

Returns:double

determinant of the matrix

getLback to summary
public RealMatrix getL()

Returns the matrix L of the decomposition.

L is a lower-triangular matrix

Returns:RealMatrix

the L matrix (or null if decomposed matrix is singular)

getPback to summary
public RealMatrix 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:RealMatrix

the P rows permutation matrix (or null if decomposed matrix is singular)

See Also
getPivot()
getPivotback to summary
public int[] getPivot()

Returns the pivot permutation vector.

Returns:int[]

the pivot permutation vector

See Also
getP()
getSolverback to summary
public DecompositionSolver getSolver()

Get a solver for finding the A × X = B solution in exact linear sense.

Returns:DecompositionSolver

a solver

getUback to summary
public RealMatrix getU()

Returns the matrix U of the decomposition.

U is an upper-triangular matrix

Returns:RealMatrix

the U matrix (or null if decomposed matrix is singular)

org.apache.commons.math3.linear back to summary

private Class LUDecomposition.Solver

extends Object
implements DecompositionSolver
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.linear.DecompositionSolver

Specialized solver.

Field Summary

Modifier and TypeField and Description
private final double[][]
lu

Entries of LU decomposition.

private final int[]
pivot

Pivot permutation associated with LU decomposition.

private final boolean
singular

Singularity indicator.

Constructor Summary

AccessConstructor and Description
private
Solver(final double[][]
entries of LU decomposition
lu
,
final int[]
pivot permutation associated with LU decomposition
pivot
,
final boolean
singularity indicator
singular
)

Build a solver from decomposed matrix.

Method Summary

Modifier and TypeMethod and Description
public RealMatrix

Returns:

the inverse matrix.
getInverse
()

Implements org.apache.commons.math3.linear.DecompositionSolver.getInverse.

Get the inverse of the decomposed matrix.

public boolean
isNonSingular()

Implements org.apache.commons.math3.linear.DecompositionSolver.isNonSingular.

Check if the decomposed matrix is non-singular.

public RealVector
solve(RealVector
right-hand side of the equation A × X = B
b
)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

public RealMatrix
solve(RealMatrix
right-hand side of the equation A × X = B
b
)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

luback to summary
private final double[][] lu

Entries of LU decomposition.

pivotback to summary
private final int[] pivot

Pivot permutation associated with LU decomposition.

singularback to summary
private final boolean singular

Singularity indicator.

Constructor Detail

Solverback to summary
private Solver(final double[][] lu, final int[] pivot, final boolean singular)

Build a solver from decomposed matrix.

Parameters
lu:double[][]

entries of LU decomposition

pivot:int[]

pivot permutation associated with LU decomposition

singular:boolean

singularity indicator

Method Detail

getInverseback to summary
public RealMatrix getInverse()

Implements org.apache.commons.math3.linear.DecompositionSolver.getInverse.

Get the inverse of the decomposed matrix.

Returns:RealMatrix

the inverse matrix.

Exceptions
SingularMatrixException:
if the decomposed matrix is singular.
isNonSingularback to summary
public boolean isNonSingular()

Implements org.apache.commons.math3.linear.DecompositionSolver.isNonSingular.

Doc from org.apache.commons.math3.linear.DecompositionSolver.isNonSingular.

Check if the decomposed matrix is non-singular.

Returns:boolean

true if the decomposed matrix is non-singular.

solveback to summary
public RealVector solve(RealVector b)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Doc from org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

The A matrix is implicit, it is provided by the underlying decomposition algorithm.

Parameters
b:RealVector

right-hand side of the equation A × X = B

Returns:RealVector

a vector X that minimizes the two norm of A × X - B

solveback to summary
public RealMatrix solve(RealMatrix b)

Implements org.apache.commons.math3.linear.DecompositionSolver.solve.

Doc from org.apache.commons.math3.linear.DecompositionSolver.solve.

Solve the linear equation A × X = B for matrices A.

The A matrix is implicit, it is provided by the underlying decomposition algorithm.

Parameters
b:RealMatrix

right-hand side of the equation A × X = B

Returns:RealMatrix

a matrix X that minimizes the two norm of A × X - B