Package cern.colt.matrix.linalg
Class QRDecomposition
java.lang.Object
cern.colt.matrix.linalg.QRDecomposition
- All Implemented Interfaces:
Serializable
For an m x n matrix A with m >= n, the QR decomposition is an m x n
orthogonal matrix Q and an n x n upper triangular matrix R so that
A = Q*R.
The QR decompostion always exists, even if the matrix does not have full rank, so the constructor will never fail. The primary use of the QR decomposition is in the least squares solution of nonsquare systems of simultaneous linear equations. This will fail if isFullRank() returns false.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Row and column dimensions.private int
Row and column dimensions.private DoubleMatrix2D
Array for internal storage of decomposition.private DoubleMatrix1D
Array for internal storage of diagonal of R.(package private) static final long
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs and returns a new QR decomposition object; computed by Householder reflections; The decomposed matrices can be retrieved via instance methods of the returned decomposition object. -
Method Summary
Modifier and TypeMethodDescriptiongetH()
Returns the Householder vectors H.getQ()
Generates and returns the (economy-sized) orthogonal factor Q.getR()
Returns the upper triangular factor, R.boolean
Returns whether the matrix A has full rank.Least squares solution of A*X = B; returns X.toString()
Returns a String with (propertyName, propertyValue) pairs.
-
Field Details
-
serialVersionUID
static final long serialVersionUID- See Also:
-
QR
Array for internal storage of decomposition. -
m
private int mRow and column dimensions. -
n
private int nRow and column dimensions. -
Rdiag
Array for internal storage of diagonal of R.
-
-
Constructor Details
-
QRDecomposition
Constructs and returns a new QR decomposition object; computed by Householder reflections; The decomposed matrices can be retrieved via instance methods of the returned decomposition object.- Parameters:
A
- A rectangular matrix.- Throws:
IllegalArgumentException
- if A.rows() invalid input: '<' A.columns().
-
-
Method Details
-
getH
Returns the Householder vectors H.- Returns:
- A lower trapezoidal matrix whose columns define the householder reflections.
-
getQ
Generates and returns the (economy-sized) orthogonal factor Q.- Returns:
- Q
-
getR
Returns the upper triangular factor, R.- Returns:
- R
-
hasFullRank
public boolean hasFullRank()Returns whether the matrix A has full rank.- Returns:
- true if R, and hence A, has full rank.
-
solve
Least squares solution of A*X = B; returns X.- Parameters:
B
- A matrix with as many rows as A and any number of columns.- Returns:
- X that minimizes the two norm of Q*R*X - B.
- Throws:
IllegalArgumentException
- if B.rows() != A.rows().IllegalArgumentException
- if !this.hasFullRank() (A is rank deficient).
-
toString
Returns a String with (propertyName, propertyValue) pairs. Useful for debugging or to quickly get the rough picture. For example,rank : 3 trace : 0
-