public class QRDecomposition
extends java.lang.Object
>=
n,
R is square with size n and Q is m X n. Otherwise, if m <
n, Q is
square with size m and R has size m X n.
Note that if m >
n, then R and M can actually have sizes p X n
and m X p, with n <=
p <=
m, with the additional rows of R
set to zero and the additional columns of Q formed by completing the
orthogonal basis.
Once constructed, a QR decomposition can be used to perform various computations related to M, such as solving equations (in particular, determining least-squares solutions), computing the determinant, or estimating the condition number.
Providing a separate class for the QR decomposition allows an application to perform such decompositions repeatedly without having to reallocate temporary storage space.
Constructor and Description |
---|
QRDecomposition()
Creates an uninitialized QRDecomposition.
|
QRDecomposition(Matrix M)
Creates a QRDecomposition for the Matrix specified by M.
|
Modifier and Type | Method and Description |
---|---|
double |
conditionEstimate()
Estimates the condition number of the triangular matrix R associated with
this decomposition.
|
double |
determinant()
Returns the determinant of the (square) upper partition of R, times the
determinant of Q.
|
void |
factor(Matrix M)
Peforms a QR decomposition on the Matrix M.
|
void |
factorInPlace(MatrixNd M)
Performs a QR decomposition on the Matrix M, placing the result in M and
using M as the storage for subsequent solve operations.
|
void |
factorWithPivoting(Matrix M)
Peforms a QR decomposition, with pivoting, on the Matrix M.
|
void |
get(MatrixNd Q,
MatrixNd R)
Gets the Q and R matrices associated with this QR decomposition.
|
void |
get(MatrixNd Q,
MatrixNd R,
int[] cperm)
Gets the Q and R matrices, and the column permutation, associated with
this QR decomposition.
|
boolean |
inverse(DenseMatrix X)
Computes the inverse of the original matrix M associated with this
decomposition, and places the result in X.
|
boolean |
leftSolveR(DenseMatrix X,
Matrix B)
Computes a left solution to the linear equation
X R = B where R is the upper triangular matrix associated with this decomposition, and X and B are matrices. |
boolean |
leftSolveR(Vector x,
Vector b)
Computes a left solution to the linear equation
x R = b where R is the upper triangular matrix associated with this decomposition, and x and b are vectors. |
static void |
main(java.lang.String[] args) |
void |
postMulQ(MatrixNd MR,
MatrixNd M1)
Computes
|
void |
postMulQTranspose(MatrixNd MR,
MatrixNd M1)
Computes
|
void |
preMulQ(MatrixNd MR,
MatrixNd M1)
Computes
|
void |
preMulQTranspose(MatrixNd MR,
MatrixNd M1)
Computes
|
int |
rank(double tol) |
boolean |
solve(DenseMatrix X,
Matrix B)
Computes a least-squares solution to 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)
Computes a least-squares solution to the linear equation
M x = b where M is the original matrix associated with this decomposition, and x and b are vectors. |
boolean |
solveR(DenseMatrix X,
Matrix B)
Computes a solution to the linear equation
R X = B where R is the upper triangular matrix associated with this decomposition, and X and B are matrices. |
boolean |
solveR(Vector x,
Vector b)
Computes a solution to the linear equation
R x = b where R is the upper triangular matrix associated with this decomposition, and x and b are vectors. |
public QRDecomposition(Matrix M)
M
- matrix to perform the QR decomposition onpublic QRDecomposition()
public void factor(Matrix M)
M
- matrix to perform the QR decomposition onpublic void factorInPlace(MatrixNd M)
public void factorWithPivoting(Matrix M)
M
- matrix to perform the QR decomposition onpublic void get(MatrixNd Q, MatrixNd R) throws ImproperStateException, ImproperSizeException
get(Q,R,cperm)
.Q
- returns the orthogonal matrixR
- returns the upper triangular matrix.ImproperStateException
- if this QRDecomposition is uninitializedImproperSizeException
- if Q or R are not of the proper dimension and cannot be resized.public void get(MatrixNd Q, MatrixNd R, int[] cperm) throws ImproperStateException, ImproperSizeException
factorWithPivoting
. Each argument is optional; values will be returned
into them if they are present. Q is an orthogonal matrix which can be m X
p, where min(n,m) <=
p <=
m (and so must be square if m
<=
n). Extra columns of Q are formed by completing the original
basis. R is an upper triangular matrix which can be q X n, where min(n,m)
<=
q <=
m (and so must be m X n if m <=
n). Extra
rows of R are set to zero.Q
- returns the orthogonal matrixR
- returns the upper triangular matrixcperm
- returns the indices of the column permutation matrix P, such that j-th
column of M P is given by column perm[j]
of M.ImproperStateException
- if this QRDecomposition is uninitializedImproperSizeException
- if Q or R are not of the proper dimension and cannot be resized.public boolean solve(Vector x, Vector b) throws ImproperStateException, ImproperSizeException
x
- unknown vector to solve forb
- constant vectorImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if M has fewer rows than columns, 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.public boolean solve(DenseMatrix X, Matrix B) throws ImproperStateException, ImproperSizeException
X
- unknown matrix to solve forB
- constant matrixImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if M has fewer rows than columns, 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.public boolean solveR(Vector x, Vector b) throws ImproperStateException, ImproperSizeException
x
- unknown vector to solve forb
- constant vectorImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if b does not have a size compatible with R, or if x does not have a size
compatible with R and cannot be resized.public boolean solveR(DenseMatrix X, Matrix B) throws ImproperStateException, ImproperSizeException
X
- unknown matrix to solve forB
- constant matrixImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if the size of B is incompatible with R, or if the size of X is
incompatible with R or B and X cannot be resized.public boolean leftSolveR(Vector x, Vector b) throws ImproperStateException, ImproperSizeException
x
- unknown vector to solve forb
- constant vectorImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if b does not have a size compatible with R, or if x does not have a size
compatible with R and cannot be resized.public boolean leftSolveR(DenseMatrix X, Matrix B) throws ImproperStateException, ImproperSizeException
X
- unknown matrix to solve forB
- constant matrixImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if the size of B is incompatible with R, or if the size of X is
incompatible with R or B and X cannot be resized.public double conditionEstimate() throws ImproperStateException
ImproperStateException
- if this QRDecomposition is uninitializedImproperSizeException
- if M has fewer rows than columns.public double determinant() throws ImproperStateException
ImproperStateException
- if this decomposition is uninitializedpublic boolean inverse(DenseMatrix X) throws ImproperStateException
X
- matrix in which the inverse is storedImproperStateException
- if this decomposition is uninitializedImproperSizeException
- if M is not square, or if X does not have the same size as M and cannot be
resized.public int rank(double tol)
public void preMulQ(MatrixNd MR, MatrixNd M1)
MR = Q M1where Q is the full m X m orthogonal matrix associated with the decomposition. Before calling this method, the decomposition must be initialized with a factorization. In order to conform with Q, M1 must have m rows.
MR
- result matrixM1
- matrix to pre-multiply by Qpublic void preMulQTranspose(MatrixNd MR, MatrixNd M1)
MR = Q^T M1where Q is the full m X m orthogonal matrix associated with the decomposition. Before calling this method, the decomposition must be initialized with a factorization. In order to conform with Q, M1 must have m rows.
MR
- result matrixM1
- matrix to pre-multiply by Q transposepublic void postMulQ(MatrixNd MR, MatrixNd M1)
MR = M1 Qwhere Q is the full m X m orthogonal matrix associated with the decomposition. Before calling this method, the decomposition must be initialized with a factorization. In order to conform with Q, M1 must have m columns.
MR
- result matrixM1
- matrix to post-multiply by Qpublic void postMulQTranspose(MatrixNd MR, MatrixNd M1)
MR = M1 Q^Twhere Q is the full m X m orthogonal matrix associated with the decomposition. Before calling this method, the decomposition must be initialized with a factorization. In order to conform with Q, M1 must have m columns.
MR
- result matrixM1
- matrix to post-multiply by Q transposepublic static void main(java.lang.String[] args)