smile.math.matrix

## Class Matrix.QR

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

```public static class Matrix.QR
extends java.lang.Object
implements java.io.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.

Serialized Form
• ### Field Summary

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

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

All Methods
Modifier and Type Method and 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 Detail

• #### qr

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

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

• #### QR

```public QR(Matrix qr,
double[] tau)```
Constructor.
• ### Method Detail

• #### CholeskyOfAtA

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

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

`public Matrix Q()`
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:
`java.lang.RuntimeException` - if 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:
`java.lang.RuntimeException` - if matrix is rank deficient.