papaya
Class LU

java.lang.Object
  extended by papaya.LU

public class LU
extends Object

LU Decomposition.

For an m x n matrix A with m > n, the LU decomposition is an m x n unit lower triangular matrix L, an n x 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 x m and U is m x n.

The LU decomposition with pivoting always exists, even if the matrix is singular, so the constructor will never fail. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations. This will fail if isNonsingular() returns false.

Shamelessly copied (and modified) from the JAMA Java Matrix package. To make things compatible with how most users use Processing, the class take in float matrices. However, to preserve the acccuracy of the computations, the algorithm first casts the input into a double array, prior to doing anything. All methods also return doubles; Use Cast.doubleToFloat(double[][]) if you want/need to cast everything back to floats for further (non-high-accuracy-dependant) processing (pun intended).


Constructor Summary
LU(float[][] A)
          Constructor.
 
Method Summary
 double det()
          Determinant
 float[] getFloatPivot()
          Return pivot permutation vector as a one-dimensional float array
 double[][] getL()
          Return lower triangular factor, L.
 int[] getPivot()
          Return pivot permutation vector
 double[][] getU()
          Return upper triangular factor, U
 boolean isNonsingular()
          Is the matrix nonsingular?
 double[][] solve(float[][] B)
          Solve A*X = B
 double[] solve(float[] b, boolean returnZeroesForSingularCase)
          Solve A*x = b for x
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LU

public LU(float[][] A)
Constructor. Takes in a matrix and computes the LU matrix. Additional parameters can be obtained by calling one of the available methods.

See Also:
getL(), getU(), getPivot(), getFloatPivot(), det()
Method Detail

isNonsingular

public boolean isNonsingular()
Is the matrix nonsingular?

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

getL

public double[][] getL()
Return lower triangular factor, L.


getU

public double[][] getU()
Return upper triangular factor, U


getPivot

public int[] getPivot()
Return pivot permutation vector

Returns:
piv

getFloatPivot

public float[] getFloatPivot()
Return pivot permutation vector as a one-dimensional float array

Returns:
piv

det

public double det()
Determinant

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

solve

public double[] solve(float[] b,
                      boolean returnZeroesForSingularCase)
Solve A*x = b for x

Parameters:
b - An array with as many elements as the number of rows in A.
Returns:
x so that L*U*x = b(piv,:)
Throws:
IllegalArgumentException - Matrix row dimensions must agree.
RuntimeException - Matrix is singular.

solve

public double[][] solve(float[][] B)
Solve A*X = B

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


Processing library papaya by Adila Faruk. (C) 2014