Class QRDecomposition
 java.lang.Object

 org.apache.commons.math4.legacy.linear.QRDecomposition

 Direct Known Subclasses:
RRQRDecomposition
public class QRDecomposition extends Object
Calculates the QRdecomposition of a matrix.The QRdecomposition of a matrix A consists of two matrices Q and R that satisfy: A = QR, Q is orthogonal (Q^{T}Q = I), and R is upper triangular. If A is m×n, Q is m×m and R m×n.
This class compute the decomposition using Householder reflectors.
For efficiency purposes, the decomposition in packed form is transposed. This allows inner loop to iterate inside rows, which is much more cacheefficient in Java.
This class is based on the class with similar name from the JAMA library, with the following changes:
 a
getQT
method has been added,  the
solve
andisFullRank
methods have been replaced by agetSolver
method and the equivalent methods provided by the returnedDecompositionSolver
.


Constructor Summary
Constructors Constructor Description QRDecomposition(RealMatrix matrix)
Calculates the QRdecomposition of the given matrix.QRDecomposition(RealMatrix matrix, double threshold)
Calculates the QRdecomposition of the given matrix.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
decompose(double[][] matrix)
Decompose matrix.RealMatrix
getH()
Returns the Householder reflector vectors.RealMatrix
getQ()
Returns the matrix Q of the decomposition.RealMatrix
getQT()
Returns the transpose of the matrix Q of the decomposition.RealMatrix
getR()
Returns the matrix R of the decomposition.DecompositionSolver
getSolver()
Get a solver for finding the A × X = B solution in least square sense.protected void
performHouseholderReflection(int minor, double[][] matrix)
Perform Householder reflection for a minor A(minor, minor) of A.



Constructor Detail

QRDecomposition
public QRDecomposition(RealMatrix matrix)
Calculates the QRdecomposition of the given matrix. The singularity threshold defaults to zero. Parameters:
matrix
 The matrix to decompose. See Also:
QRDecomposition(RealMatrix,double)

QRDecomposition
public QRDecomposition(RealMatrix matrix, double threshold)
Calculates the QRdecomposition of the given matrix. Parameters:
matrix
 The matrix to decompose.threshold
 Singularity threshold. The matrix will be considered singular if the absolute value of any of the diagonal elements of the "R" matrix is smaller than the threshold.


Method Detail

decompose
protected void decompose(double[][] matrix)
Decompose matrix. Parameters:
matrix
 transposed matrix Since:
 3.2

performHouseholderReflection
protected void performHouseholderReflection(int minor, double[][] matrix)
Perform Householder reflection for a minor A(minor, minor) of A. Parameters:
minor
 minor indexmatrix
 transposed matrix Since:
 3.2

getR
public RealMatrix getR()
Returns the matrix R of the decomposition.R is an uppertriangular matrix
 Returns:
 the R matrix

getQ
public RealMatrix getQ()
Returns the matrix Q of the decomposition.Q is an orthogonal matrix
 Returns:
 the Q matrix

getQT
public RealMatrix getQT()
Returns the transpose of the matrix Q of the decomposition.Q is an orthogonal matrix
 Returns:
 the transpose of the Q matrix, Q^{T}

getH
public RealMatrix getH()
Returns the Householder reflector vectors.H is a lower trapezoidal matrix whose columns represent each successive Householder reflector vector. This matrix is used to compute Q.
 Returns:
 a matrix containing the Householder reflector vectors

getSolver
public DecompositionSolver getSolver()
Get a solver for finding the A × X = B solution in least square sense.Least Square sense means a solver can be computed for an overdetermined system, (i.e. a system with more equations than unknowns, which corresponds to a tall A matrix with more rows than columns). In any case, if the matrix is singular within the tolerance set at
construction
, an error will be triggered when thesolve
method will be called. Returns:
 a solver

