maspack.matrix

## Class LUDecomposition

• java.lang.Object
• maspack.matrix.LUDecomposition

• ```public class LUDecomposition
extends java.lang.Object```
Constructs the LU decomposition of a square matrix. This takes the form
P M = L U
where P is a permutation matrix, M is the original matrix, L is unit-lower-triangular, and U is upper-triangular. Once an LU decomposition has been constructed, it can be used to perform various computations related to M, such as solving equations, computing the determinant, or estimating the condition number.

Providing a separate class for the LU decomposition allows an application to perform such decompositions repeatedly without having to reallocate temporary storage space.

• ### Constructor Summary

Constructors
Constructor and Description
`LUDecomposition()`
Creates an uninitialized LUDecomposition.
`LUDecomposition(int n)`
Creates an uninitialized LUDecomposition with enough capacity to handle matrices of size `n`.
`LUDecomposition(Matrix M)`
Creates an LUDecomposition for the Matrix specified by M.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `conditionEstimate(Matrix M)`
Estimates the condition number of the original matrix M associated with this decomposition.
`double` `determinant()`
Compute the determinant of the original matrix M associated with this decomposition.
`void` `factor(Matrix M)`
Peforms an LU decomposition on the Matrix M.
`void` ```get(MatrixNd L, MatrixNd U, int[] rperm)```
Gets the matrices associated with the LU decomposition.
`boolean` `inverse(DenseMatrix R)`
Computes the inverse of the original matrix M associated with this decomposition, and places the result in R.
`boolean` ```solve(DenseMatrix X, Matrix B)```
Solves the linear equation
M X = B
where M is the original matrix associated with this decomposition, and X and B are matrices.
`boolean` ```solve(Vector x, Vector b)```
Solves the linear equation
M x = b
where M is the original matrix associated with this decomposition, and x and b are vectors.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### LUDecomposition

`public LUDecomposition()`
Creates an uninitialized LUDecomposition.
• #### LUDecomposition

`public LUDecomposition(int n)`
Creates an uninitialized LUDecomposition with enough capacity to handle matrices of size `n`. This capacity will later be increased on demand.
Parameters:
`n` - initial maximum matrix size
• #### LUDecomposition

```public LUDecomposition(Matrix M)
throws ImproperSizeException```
Creates an LUDecomposition for the Matrix specified by M.
Parameters:
`M` - matrix to perform the LU decomposition on
Throws:
`ImproperSizeException` - if M is not square
• ### Method Detail

• #### factor

```public void factor(Matrix M)
throws ImproperSizeException```
Peforms an LU decomposition on the Matrix M.
Parameters:
`M` - matrix to perform the LU decomposition on
Throws:
`ImproperSizeException` - if M is not square
• #### get

```public void get(MatrixNd L,
MatrixNd U,
int[] rperm)
throws ImproperStateException,
ImproperSizeException```
Gets the matrices associated with the LU decomposition. Each argument is optional; values will be returned into them if they are present.
Parameters:
`L` - unit lower triangular matrix
`U` - upper triangular matrix
`rperm` - indices of the row permuation matrix P, such that the i-th row of P M is given by row `perm[i]` of M.
Throws:
`ImproperStateException` - if this LUDecomposition is uninitialized
`ImproperSizeException` - if L or U are not of the proper dimension and cannot be resized, or if the length of perm is less than the size of M.
• #### solve

```public boolean solve(Vector x,
Vector b)
throws ImproperStateException,
ImproperSizeException```
Solves the linear equation
M x = b
where M is the original matrix associated with this decomposition, and x and b are vectors.
Parameters:
`x` - unknown vector to solve for
`b` - constant vector
Returns:
false if M is singular (within working precision)
Throws:
`ImproperStateException` - if this decomposition is uninitialized
`ImproperSizeException` - if b does not have a size compatible with M, or if x does not have a size compatible with M and cannot be resized.
• #### solve

```public boolean solve(DenseMatrix X,
Matrix B)
throws ImproperStateException,
ImproperSizeException```
Solves the linear equation
M X = B
where M is the original matrix associated with this decomposition, and X and B are matrices.
Parameters:
`X` - unknown matrix to solve for
`B` - constant matrix
Returns:
false if M is singular (within working precision)
Throws:
`ImproperStateException` - if this decomposition is uninitialized
`ImproperSizeException` - if B has a different number of rows than M, or if X has a different number of rows than M or a different number of columns than B and cannot be resized.
• #### conditionEstimate

```public double conditionEstimate(Matrix M)
throws ImproperStateException,
ImproperSizeException```
Estimates the condition number of the original matrix M associated with this decomposition. M must also be supplied as an argument. The algorithm for estimating the condition number is given in Section 3.5.4 of Golub and Van Loan, Matrix Computations (Second Edition).
Parameters:
`M` - original matrix
Returns:
condition number estimate
Throws:
`ImproperStateException` - if this LUDecomposition is uninitialized
`ImproperSizeException` - if the size of M does not match the size of the current LU decomposition
• #### determinant

```public double determinant()
throws ImproperStateException```
Compute the determinant of the original matrix M associated with this decomposition.
Returns:
determinant
Throws:
`ImproperStateException` - if this decomposition is uninitialized
• #### inverse

```public boolean inverse(DenseMatrix R)
throws ImproperStateException```
Computes the inverse of the original matrix M associated with this decomposition, and places the result in R.
Parameters:
`R` - matrix in which the inverse is stored
Returns:
false if M is singular (within working precision)
Throws:
`ImproperStateException` - if this decomposition is uninitialized
`ImproperSizeException` - if R does not have the same size as M and cannot be resized.