# qr#

## Purpose#

Computes the orthogonal-triangular (QR) decomposition of a matrix x, such that: $$X = Q_1R$$

## Format#

r = qr(x)#
Parameters:

x (NxP matrix) – data

Returns:

r (KxP matrix) – upper triangular matrix, $$K = min(N,P)$$.

## Remarks#

qr() is the same as qqr() but doesn’t return the $$Q_1$$ matrix. If $$Q_1$$ is not wanted, qr() will save a significant amount of time and memory usage, especially for large problems.

Given $$X$$, there is an orthogonal matrix $$Q$$ such that $$Q'X$$ is zero below its diagonal, i.e.,

$\begin{split}Q′X = \begin{bmatrix} R \\ 0 \end{bmatrix}\end{split}$

where $$R$$ is upper triangular. If we partition

$Q⁢ = \begin{bmatrix} Q_1 & Q_2 \end{bmatrix}$

where $$Q_1$$ has $$P$$ columns, then

$X⁢ = Q_1⁢R$

is the QR decomposition of $$X$$. If $$X$$ has linearly independent columns, $$R$$ is also the Cholesky factorization of the moment matrix of $$X$$, i.e., of $$X'X$$.

qr() does not return the $$Q_1$$ matrix because in most cases it is not required and can be very large. If you need the $$Q_1$$ matrix, see the function qqr(). If you need the entire $$Q$$ matrix, call qyr() with $$Y$$ set to a conformable identity matrix.

For most problems $$Q'Y$$, $$Q_1'Y$$, or $$QY$$, $$Q_1Y$$, for some $$Y$$, are required. For these cases see qtyr() and qyr().

For linear equation or least squares problems, which require $$Q_2$$ for computing residuals and residual sums of squares, see olsqr().

If $$N < P$$, the factorization assumes the form:

$Q'X = \begin{bmatrix} R_1 & R_2 \end{bmatrix}$

where $$R_1$$ is a PxP upper triangular matrix and $$R_2$$ is $$P \times (N-P)$$. Thus $$Q$$ is a PxP matrix and $$R$$ is a PxN matrix containing $$R_1$$ and $$R_2$$. This type of factorization is useful for the solution of underdetermined systems. However, unless the linearly independent columns happen to be the initial rows, such an analysis also requires pivoting (see qre() and qrep()).

qr.src