Package smile.math.matrix
Class LU
- java.lang.Object
-
- smile.math.matrix.LU
-
public class LU extends java.lang.Object
For an m-by-n matrix A with m ≥ n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a permutation vector piv of length m so that A(piv,:) = L*U. If m < n, then L is m-by-m and U is m-by-n.The LU decomposition with pivoting always exists, even if the matrix is singular. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations if it is not singular.
This decomposition can also be used to calculate the determinant.
- Author:
- Haifeng Li
-
-
Field Summary
Fields Modifier and Type Field Description protected DenseMatrix
lu
Array for internal storage of decomposition.protected int[]
piv
Internal storage of pivot vector.protected int
pivsign
pivot sign.protected boolean
singular
True if the matrix is singular.
-
Constructor Summary
Constructors Constructor Description LU(DenseMatrix lu, int[] piv, boolean singular)
Constructor.LU(DenseMatrix lu, int[] piv, int pivsign, boolean singular)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
det()
Returns the matrix determinantDenseMatrix
inverse()
Returns the matrix inverse.boolean
isSingular()
Returns true if the matrix is singular or false otherwise.void
solve(double[] b)
Solve A * x = b.void
solve(DenseMatrix B)
Solve A * X = B.
-
-
-
Field Detail
-
lu
protected DenseMatrix lu
Array for internal storage of decomposition.
-
pivsign
protected int pivsign
pivot sign.
-
piv
protected int[] piv
Internal storage of pivot vector.
-
singular
protected boolean singular
True if the matrix is singular.
-
-
Constructor Detail
-
LU
public LU(DenseMatrix lu, int[] piv, int pivsign, boolean singular)
Constructor.- Parameters:
lu
- LU decomposition matrixpiv
- pivot vectorpivsign
- pivot sign. +1 if even number of row interchanges, -1 if odd number of row interchanges.singular
- True if the matrix is singular
-
LU
public LU(DenseMatrix lu, int[] piv, boolean singular)
Constructor.- Parameters:
lu
- LU decomposition matrixpiv
- pivot vectorsingular
- True if the matrix is singular
-
-
Method Detail
-
isSingular
public boolean isSingular()
Returns true if the matrix is singular or false otherwise.
-
det
public double det()
Returns the matrix determinant
-
inverse
public DenseMatrix inverse()
Returns the matrix inverse. For pseudo inverse, use QRDecomposition.
-
solve
public void solve(double[] b)
Solve A * x = b.- Parameters:
b
- right hand side of linear system. On output, b will be overwritten with the solution matrix.- Throws:
java.lang.RuntimeException
- if matrix is singular.
-
solve
public void solve(DenseMatrix B)
Solve A * X = B. B will be overwritten with the solution matrix on output.- Parameters:
B
- right hand side of linear system. On output, B will be overwritten with the solution matrix.- Throws:
java.lang.RuntimeException
- if matrix is singular.
-
-