org.apache.commons.math3.linear

## Class QRDecomposition

- java.lang.Object
- - org.apache.commons.math3.linear.QRDecomposition

-     public class QRDecomposition
      extends Object

  Calculates the QR-decomposition of a matrix.

  The QR-decomposition of a matrix A consists of two matrices Q and R that satisfy: A = QR, Q is orthogonal (QTQ = 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 cache-efficient 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` and `isFullRank` methods have been replaced by a `getSolver` method and the equivalent methods provided by the returned `DecompositionSolver`.
  Since:
    1.2 (changed to concrete class in 3.0)
  Version:
    $Id: QRDecomposition.java 1416643 2012-12-03 19:37:14Z tn $
  See Also:
    MathWorld, Wikipedia

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `private static class` | `QRDecomposition.Solver` Specialized solver.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private RealMatrix` | `cachedH` Cached value of H.
    `private RealMatrix` | `cachedQ` Cached value of Q.
    `private RealMatrix` | `cachedQT` Cached value of QT.
    `private RealMatrix` | `cachedR` Cached value of R.
    `private double[][]` | `qrt` A packed TRANSPOSED representation of the QR decomposition.
    `private double[]` | `rDiag` The diagonal elements of R.
    `private double` | `threshold` Singularity threshold.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `QRDecomposition(RealMatrix matrix)` Calculates the QR-decomposition of the given matrix.
    `QRDecomposition(RealMatrix matrix, double threshold)` Calculates the QR-decomposition of the given matrix.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### qrt

          private double[][] qrt

      A packed TRANSPOSED representation of the QR decomposition.

      The elements BELOW the diagonal are the elements of the UPPER triangular matrix R, and the rows ABOVE the diagonal are the Householder reflector vectors from which an explicit form of Q can be recomputed if desired.

    - #### rDiag

          private double[] rDiag

      The diagonal elements of R.

    - #### cachedQ

          private RealMatrix cachedQ

      Cached value of Q.

    - #### cachedQT

          private RealMatrix cachedQT

      Cached value of QT.

    - #### cachedR

          private RealMatrix cachedR

      Cached value of R.

    - #### cachedH

          private RealMatrix cachedH

      Cached value of H.

    - #### threshold

          private final double threshold

      Singularity threshold.

  - ### Constructor Detail

    - #### QRDecomposition

          public QRDecomposition(RealMatrix matrix)

      Calculates the QR-decomposition 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 QR-decomposition of the given matrix.
      Parameters:
        `matrix` - The matrix to decompose.
        `threshold` - Singularity threshold.

  - ### Method Detail

    - #### getR

          public RealMatrix getR()

      Returns the matrix R of the decomposition.

      R is an upper-triangular 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, QT

    - #### 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.
      Returns:
        a solver

Copyright (c) 2003-2013 Apache Software Foundation