# qqr¶

## Purpose¶

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

## Format¶

{ q1, r } = qqr(x)
Parameters

x (NxP matrix) – data

Returns
• q1 (NxK matrix) – unitary matrix, $$K = min(N, P)$$.

• r (KxP matrix) – upper triangular matrix

## Remarks¶

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$$.

If you want only the $$R$$ matrix, see the function qr(). Not computing $$Q_1$$ can produce significant improvements in computing time and memory usage.

An unpivoted $$R$$ matrix can also be generated using cholup():

r = cholup(zeros(cols(x), cols(x)), x);


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

For most problems an explicit copy of $$Q_1$$ or $$Q_2$$ is not required. Instead one of the following, $$Q'Y$$, $$QY$$, $$Q_1Y$$, $$Q_1'Y$$, $$Q_2Y$$, or $$Q_2'Y$$, for some $$Y$$, is required. These cases are all handled by qtyr() and qyr(). These functions are available because $$Q$$ and $$Q_1$$ are typically very large matrices while their products with $$Y$$ are more manageable.

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()).

qqr.src