mpv2
Class LUPDecomposition

java.lang.Object
  extended by mpv2.LUPDecomposition
All Implemented Interfaces:
java.io.Serializable

public class LUPDecomposition
extends java.lang.Object
implements java.io.Serializable

LUP Decomposition, P*A = L*U A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

See Also:
Serialized Form

Constructor Summary
LUPDecomposition(AllMatrices A)
          LUP Decomposition, P*A = L*U Constructor returns a structure to access L, U and P.
LUPDecomposition(double[] vals)
          LUP Decomposition, P*A = L*U.
LUPDecomposition(int N, int K, double[] vals)
          LUP Decomposition, P*A = L*U Constructor returns a structure to access L, U and P.
 
Method Summary
 double det()
          Determinant
 int getK()
          Get number of columns in the original matrix A, i.e. length of each row vector.
 double[] getLArray()
          Return lower triangular factor as a column-ordered array of length N*M.
 BandMatrix getLMatrix()
          Return lower triangular factor as a BandMatrix object.
 int getM()
          Get number of columns in L and rows in U.
 int getN()
          Get number of rows in the original matrix A, i.e. length of each column vector.
 int[] getPivot()
          Return pivot permutation vector, P(n,k)=1 when p[n]=k.
 PermutationMatrix getPmatrix()
          Return the permutation matrix, P as a PermutationMatrix object.
 double[] getUArray()
          Return upper triangular factor as a column-ordered array of length M*K.
 BandMatrix getUMatrix()
          Return upper triangular factor as a BandMatrix object.
 boolean isNonsingular()
          Is the matrix nonsingular?
 double[] solveArray(AllMatrices B)
          Solve A*X = B, X is returned as an array.
 double[] solveArray(double[] b)
          Solve A*x = b
 SimpleMatrix solveMatrix(AllMatrices B)
          Solve A*X = B, X is returned as a SimpleMatrix object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LUPDecomposition

public LUPDecomposition(AllMatrices A)
LUP Decomposition, P*A = L*U Constructor returns a structure to access L, U and P.

Parameters:
A - Rectangular matrix of any AllMatrices type

LUPDecomposition

public LUPDecomposition(int N,
                        int K,
                        double[] vals)
LUP Decomposition, P*A = L*U Constructor returns a structure to access L, U and P.

Parameters:
N - Number of rows in the matrix
K - Number of columns in the matrix
vals - The (N*K) matrix elements ordered by columns in an array
Throws:
java.lang.IllegalArgumentException

LUPDecomposition

public LUPDecomposition(double[] vals)
LUP Decomposition, P*A = L*U. Constructor returns a structure to access L, U and P. The dimension of the matrix is assumed to be square and given by the length of the vals array.

Parameters:
vals - The (N*N) matrix elements ordered by columns in an array
Throws:
java.lang.IllegalArgumentException
Method Detail

getN

public int getN()
Get number of rows in the original matrix A, i.e. length of each column vector. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
N, the number of rows in A

getK

public int getK()
Get number of columns in the original matrix A, i.e. length of each row vector. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
K, the number of columns in A

getM

public int getM()
Get number of columns in L and rows in U. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
M, the number of columns in L and rows in U

isNonsingular

public boolean isNonsingular()
Is the matrix nonsingular?

Returns:
true if U, and hence A, is nonsingular.

getLMatrix

public BandMatrix getLMatrix()
Return lower triangular factor as a BandMatrix object. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
LMatrix

getLArray

public double[] getLArray()
Return lower triangular factor as a column-ordered array of length N*M. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
Larray

getUMatrix

public BandMatrix getUMatrix()
Return upper triangular factor as a BandMatrix object. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
UMatrix

getUArray

public double[] getUArray()
Return upper triangular factor as a column-ordered array of length M*K. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
Uarray

getPivot

public int[] getPivot()
Return pivot permutation vector, P(n,k)=1 when p[n]=k. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
p

getPmatrix

public PermutationMatrix getPmatrix()
Return the permutation matrix, P as a PermutationMatrix object. LUP-decomposition is P*A = L*U, where A is N-by-K, P is N-by-N, M is Math.min(N,K), then L is N-by-M and U is M-by-K

Returns:
P, the permutation matrix

det

public double det()
Determinant

Returns:
det(A)
Throws:
java.lang.IllegalArgumentException - Matrix must be square

solveArray

public double[] solveArray(double[] b)
Solve A*x = b

Parameters:
b - An array with as many elements as rows in A.
Returns:
The values in x, x so that L*U*x = P*b
Throws:
java.lang.IllegalArgumentException - Matrix row dimensions must agree.
java.lang.RuntimeException - Matrix is singular.

solveMatrix

public SimpleMatrix solveMatrix(AllMatrices B)
Solve A*X = B, X is returned as a SimpleMatrix object.

Parameters:
B - A Matrix with as many rows as A and any number of columns.
Returns:
A SimpleMatrix X so that L*U*X = P*B
Throws:
java.lang.IllegalArgumentException - Matrix row dimensions must agree.
java.lang.RuntimeException - Matrix is singular.

solveArray

public double[] solveArray(AllMatrices B)
Solve A*X = B, X is returned as an array. An array with the values of X is returned, but B can be any matrix, i.e. a descendant of AllMatrices. This is perhaps a little bit faster than the solveMatrix method which return a SimpleMatrix object.

Parameters:
B - A Matrix with as many rows as A and any number of columns.
Returns:
The values in X ordered by columns, X so that L*U*X = P*B
Throws:
java.lang.IllegalArgumentException - Matrix row dimensions must agree.
java.lang.RuntimeException - Matrix is singular.