# Class Matrix.QR

java.lang.Object
smile.math.matrix.Matrix.QR
All Implemented Interfaces:
`Serializable`
Enclosing class:
`Matrix`

public static class Matrix.QR extends Object implements Serializable
The QR decomposition. For an m-by-n matrix A with `m >= n`, the QR decomposition is an m-by-n orthogonal matrix Q and an n-by-n upper triangular matrix R such that A = Q*R.

The QR decomposition always exists, even if the matrix does not have full rank. The primary use of the QR decomposition is in the least squares solution of non-square systems of simultaneous linear equations.

• ## Field Summary

Fields
Modifier and Type
Field
Description
`final Matrix`
`qr`
The QR decomposition.
`final double[]`
`tau`
The scalar factors of the elementary reflectors
• ## Constructor Summary

Constructors
Constructor
Description
```QR(Matrix qr, double[] tau)```
Constructor.
• ## Method Summary

Modifier and Type
Method
Description
`Matrix.Cholesky`
`CholeskyOfAtA()`
Returns the Cholesky decomposition of A'A.
`Matrix`
`Q()`
Returns the orthogonal factor.
`Matrix`
`R()`
Returns the upper triangular factor.
`double[]`
`solve(double[] b)`
Solves the least squares min || B - A*X ||.
`void`
`solve(Matrix B)`
Solves the least squares min || B - A*X ||.

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ## Field Details

• ### qr

public final Matrix qr
The QR decomposition.
• ### tau

public final double[] tau
The scalar factors of the elementary reflectors
• ## Constructor Details

• ### QR

public QR(Matrix qr, double[] tau)
Constructor.
Parameters:
`qr` - the QR decomposition.
`tau` - the scalar factors of the elementary reflectors
• ## Method Details

• ### CholeskyOfAtA

public Matrix.Cholesky CholeskyOfAtA()
Returns the Cholesky decomposition of A'A.
Returns:
the Cholesky decomposition of A'A.
• ### R

public Matrix R()
Returns the upper triangular factor.
Returns:
the upper triangular factor.
• ### Q

public Matrix Q()
Returns the orthogonal factor.
Returns:
the orthogonal factor.
• ### solve

public double[] solve(double[] b)
Solves the least squares min || B - A*X ||.
Parameters:
`b` - the right hand side of overdetermined linear system.
Returns:
the solution vector beta that minimizes ||Y - X*beta||.
Throws:
`RuntimeException` - when the matrix is rank deficient.
• ### solve

public void solve(Matrix B)
Solves the least squares min || B - A*X ||.
Parameters:
`B` - the right hand side of overdetermined linear system. B will be overwritten with the solution matrix on output.
Throws:
`RuntimeException` - when the matrix is rank deficient.