cern.colt.matrix.tfloat.algo.decomposition.DenseFloatLUDecomposition Maven / Gradle / Ivy
Show all versions of parallelcolt Show documentation
/*
Copyright (C) 1999 CERN - European Organization for Nuclear Research.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
is hereby granted without fee, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation.
CERN makes no representations about the suitability of this software for any purpose.
It is provided "as is" without expressed or implied warranty.
*/
package cern.colt.matrix.tfloat.algo.decomposition;
import cern.colt.matrix.tfloat.FloatMatrix1D;
import cern.colt.matrix.tfloat.FloatMatrix2D;
/**
* 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.
*/
public class DenseFloatLUDecomposition implements java.io.Serializable {
static final long serialVersionUID = 1020;
protected DenseFloatLUDecompositionQuick quick;
/**
* Constructs and returns a new LU Decomposition object; The decomposed
* matrices can be retrieved via instance methods of the returned
* decomposition object.
*
* @param A
* Rectangular matrix
*/
public DenseFloatLUDecomposition(FloatMatrix2D A) {
quick = new DenseFloatLUDecompositionQuick(0); // zero tolerance for
// compatibility with Jama
quick.decompose(A.copy());
}
/**
* Returns the determinant, det(A).
*
* @exception IllegalArgumentException
* Matrix must be square
*/
public float det() {
return quick.det();
}
/**
* Returns the lower triangular factor, L.
*
* @return L
*/
public FloatMatrix2D getL() {
return quick.getL();
}
/**
* Returns a copy of the pivot permutation vector.
*
* @return piv
*/
public int[] getPivot() {
return quick.getPivot().clone();
}
/**
* Returns the upper triangular factor, U.
*
* @return U
*/
public FloatMatrix2D getU() {
return quick.getU();
}
/**
* Returns whether the matrix is nonsingular (has an inverse).
*
* @return true if U, and hence A, is nonsingular; false
* otherwise.
*/
public boolean isNonsingular() {
return quick.isNonsingular();
}
/**
* Solves A*X = B.
*
* @param B
* A matrix with as many rows as A and any number of
* columns.
* @return X so that L*U*X = B(piv).
* @exception IllegalArgumentException
* if B.rows() != A.rows().
* @exception IllegalArgumentException
* if A is singular, that is, if
* !this.isNonsingular().
* @exception IllegalArgumentException
* if A.rows() < A.columns().
*/
public FloatMatrix2D solve(FloatMatrix2D B) {
FloatMatrix2D X = B.copy();
quick.solve(X);
return X;
}
/**
* Solves A*x = b.
*
* @param b
* A vector of size A.rows()
* @return x so that L*U*x = b(piv).
* @exception IllegalArgumentException
* if b.size() != A.rows().
* @exception IllegalArgumentException
* if A is singular, that is, if
* !this.isNonsingular().
* @exception IllegalArgumentException
* if A.rows() < A.columns().
*/
public FloatMatrix1D solve(FloatMatrix1D b) {
FloatMatrix1D x = b.copy();
quick.solve(x);
return x;
}
/**
* Returns a String with (propertyName, propertyValue) pairs. Useful for
* debugging or to quickly get the rough picture. For example,
*
*
* rank : 3
* trace : 0
*
*
*/
public String toString() {
return quick.toString();
}
}