Tutorials › Linear Algebra › QR Factorization For Rank-Deficient Matrices

Least Squares and QR Factorization · Tutorial 700 of 1000

QR Factorization For Rank-Deficient Matrices

You will learn to skip zero Gram–Schmidt residuals, complete the resulting orthonormal set, and verify a full QR factorization for tall and wide matrices.

Intermediate 9 min read

What You'll Learn

  • Define full QR factorization and its matrix dimensions.
  • Apply Gram–Schmidt without dividing by a zero residual.
  • Complete an orthonormal set to a basis of the ambient space.
  • Prove why the resulting factorization has the required zero entries.
  • Verify full QR factorizations for tall and wide rank-deficient matrices.

Why Rank Deficiency Needs a Careful QR Construction

Gram–Schmidt turns independent columns into orthonormal vectors. If a column is dependent on the columns already processed, however, its Gram–Schmidt residual is zero, so it cannot be normalized. That does not prevent a QR factorization: it means we must skip that residual, continue processing later columns, and then complete the orthonormal set to a basis of the ambient space.

Throughout, matrices and vectors have real entries, and vectors are columns. Let \(\mathbf{A}\in\mathbb{R}^{m\times n}\) have columns \(\mathbf{a}_1,\dots,\mathbf{a}_n\). A full QR factorization uses a square matrix \(\mathbf{Q}\) with \(m\) orthonormal columns and a matrix \(\mathbf{R}\) with \(m\) rows. The dimensions matter for wide matrices as well as tall ones.

Definition: A full QR factorization of \(\mathbf{A}\in\mathbb{R}^{m\times n}\) is an equality \(\mathbf{A}=\mathbf{Q}\mathbf{R}\), where \(\mathbf{Q}\in\mathbb{R}^{m\times m}\) has orthonormal columns and \(\mathbf{R}\in\mathbb{R}^{m\times n}\) is upper trapezoidal, meaning \(r_{ij}=0\) whenever \(i>j\). A square matrix with orthonormal columns is called orthogonal.

In particular, \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{I}_m\). The first \(r\) columns of \(\mathbf{Q}\), where \(r\) is the rank of \(\mathbf{A}\), can be chosen to span the column space of \(\mathbf{A}\). The remaining columns complete them to an orthonormal basis of \(\mathbb{R}^m\). Consequently, the last \(m-r\) rows of \(\mathbf{R}\) are zero. If \(n>m\), then \(\mathbf{R}\) is still \(m\times n\); it has no rows beyond row \(m\).

The Construction and Why It Works

Process the columns in their given order. For a column \(\mathbf{a}_j\), subtract its projections onto the orthonormal vectors already constructed. A nonzero remainder supplies a new orthonormal vector; a zero remainder is skipped. After all columns have been processed, complete the orthonormal set using vectors from the standard basis of \(\mathbb{R}^m\), applying the same projection-and-normalization step.

1
Process the columns.
If the vectors already accepted are \(\mathbf{q}_1,\dots,\mathbf{q}_s\), form \(\mathbf{w}_j=\mathbf{a}_j-\sum_{i=1}^{s}(\mathbf{q}_i\cdot\mathbf{a}_j)\mathbf{q}_i\). If \(\mathbf{w}_j\ne\mathbf{0}\), append \(\mathbf{w}_j/\|\mathbf{w}_j\|\). If \(\mathbf{w}_j=\mathbf{0}\), append nothing.
2
Complete the orthonormal set.
Process \(\mathbf{e}_1,\dots,\mathbf{e}_m\) in turn by subtracting their projections onto the current list. Append and normalize each nonzero remainder until the list has \(m\) vectors.
3
Form the factors.
Put the \(m\) orthonormal vectors into the columns of \(\mathbf{Q}\), and set \(r_{ij}=\mathbf{q}_i\cdot\mathbf{a}_j\). These entries form \(\mathbf{R}\).

The zero test is essential: normalization means dividing by the norm, and \(\|\mathbf{0}\|=0\). Skipping a zero remainder does not lose information, because that column is already in the span of the vectors constructed so far. Continuing through the columns is also essential: a later column can add a new direction even when an earlier column was dependent.

Lemma: If \(\mathbf{Q}\in\mathbb{R}^{m\times m}\) has orthonormal columns and \(\mathbf{R}=\mathbf{Q}^{\top}\mathbf{A}\), then \(\mathbf{Q}\mathbf{R}=\mathbf{A}\).

Proof. The \(m\) orthonormal columns of \(\mathbf{Q}\) are linearly independent: if \(\sum_{i=1}^m c_i\mathbf{q}_i=\mathbf{0}\), taking the dot product with \(\mathbf{q}_k\) gives \(c_k=0\) for each \(k\). Since \(m\) linearly independent vectors in \(\mathbb{R}^m\) form a basis, write any column \(\mathbf{a}_j\) as \(\mathbf{a}_j=\sum_{i=1}^m c_i\mathbf{q}_i\). Taking the dot product with \(\mathbf{q}_k\) gives \(c_k=\mathbf{q}_k\cdot\mathbf{a}_j=r_{kj}\). Thus the \(j\)th column of \(\mathbf{Q}\mathbf{R}\) is \(\sum_{i=1}^m r_{ij}\mathbf{q}_i=\mathbf{a}_j\). This holds for every column, so \(\mathbf{Q}\mathbf{R}=\mathbf{A}\). \(\square\)

Theorem (Existence of full QR factorization): Every real matrix \(\mathbf{A}\in\mathbb{R}^{m\times n}\), with \(m,n\geq 1\), has a full QR factorization. This includes matrices with dependent columns and matrices with more columns than rows.

Proof. Process the columns using the construction above. Each new nonzero residual is orthogonal to every previously accepted vector: for any previous \(\mathbf{q}_i\), the projection-subtraction formula gives \(\mathbf{q}_i\cdot\mathbf{w}_j=0\). Normalizing such a residual therefore preserves orthonormality. Also, after processing column \(j\), the accepted vectors span \(\mathbf{a}_1,\dots,\mathbf{a}_j\): each column equals the sum of its projections onto the current vectors and its residual; that residual is either zero or is added to the list. Induction over \(j\) proves the spanning claim. Thus, after all columns are processed, the accepted vectors are an orthonormal basis for \(\operatorname{Col}\mathbf{A}\).

Now process the standard basis vectors and append every nonzero residual. Each appended vector is orthogonal to the existing list, so orthonormality is preserved. This procedure must eventually produce \(m\) vectors: if it stopped with fewer, then each standard basis vector would lie in the final span, because its residual was either zero or was appended. The final span would then contain all of \(\mathbb{R}^m\), which cannot be spanned by fewer than \(m\) linearly independent vectors. Put the resulting \(m\) vectors into \(\mathbf{Q}\), and define \(\mathbf{R}=\mathbf{Q}^{\top}\mathbf{A}\). The lemma gives \(\mathbf{Q}\mathbf{R}=\mathbf{A}\).

It remains to check the required zero entries. For each \(i\leq m\), either \(\mathbf{q}_i\) was produced from a nonzero residual at some column \(k_i\), or it was added during completion. The column indices \(k_i\) for vectors produced from columns increase with \(i\). If \(i>j\) and \(\mathbf{q}_i\) came from column \(k_i\), then \(k_i\geq i>j\). When it was constructed, \(\mathbf{q}_i\) was orthogonal to every earlier column, including \(\mathbf{a}_j\), which lies in the span of the columns before \(k_i\). If \(\mathbf{q}_i\) was added during completion, it is orthogonal to every column of \(\mathbf{A}\). In either case \(r_{ij}=\mathbf{q}_i\cdot\mathbf{a}_j=0\). Hence \(\mathbf{R}\) is upper trapezoidal, as required. \(\square\)

Worked Factorizations

Worked Example: Dependent Columns in a Tall Matrix

Factor the \(3\times 3\) matrix with columns \((1,1,0)^{\top}\), \((1,-1,0)^{\top}\), and \((2,0,0)^{\top}\). The third column is the sum of the first two, so the rank is \(2\).

The first two columns have norm \(\sqrt{2}\) and dot product \(0\). Choose \(\mathbf{q}_1=(1,1,0)^{\top}/\sqrt{2}\) and \(\mathbf{q}_2=(1,-1,0)^{\top}/\sqrt{2}\). Their orthogonal complement in \(\mathbb{R}^3\) includes \(\mathbf{q}_3=(0,0,1)^{\top}\). The projection coefficients give

$$ \mathbf{Q}=\begin{bmatrix} 1/\sqrt{2}&1/\sqrt{2}&0\\ 1/\sqrt{2}&-1/\sqrt{2}&0\\ 0&0&1 \end{bmatrix}, \qquad \mathbf{R}=\begin{bmatrix} \sqrt{2}&0&\sqrt{2}\\ 0&\sqrt{2}&\sqrt{2}\\ 0&0&0 \end{bmatrix}. $$

The columns of \(\mathbf{Q}\) each have norm \(1\), and their pairwise dot products are \(0\), so \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{I}_3\). Multiplying column by column, \(\mathbf{Q}\) times the first column of \(\mathbf{R}\) gives \((1,1,0)^{\top}\); the second gives \((1,-1,0)^{\top}\); and the third gives \((2,0,0)^{\top}\). Thus \(\mathbf{Q}\mathbf{R}=\mathbf{A}\). The zero third row of \(\mathbf{R}\) reflects that the columns of \(\mathbf{A}\) lie in a two-dimensional subspace.

Worked Example: A Wide Matrix with a Dependent Column

Consider the \(2\times 3\) matrix whose columns are \((1,1)^{\top}\), \((2,2)^{\top}\), and \((1,-1)^{\top}\). The second column is twice the first, while the third is independent of the first. The rank is \(2\), less than the number of columns.

From the first column, take \(\mathbf{q}_1=(1,1)^{\top}/\sqrt{2}\). The residual for the second column is \((2,2)^{\top}-2\sqrt{2}\mathbf{q}_1=\mathbf{0}\), so skip it. The third column is orthogonal to \(\mathbf{q}_1\), so take \(\mathbf{q}_2=(1,-1)^{\top}/\sqrt{2}\). These two vectors complete an orthonormal basis of \(\mathbb{R}^2\). The factors are

$$ \mathbf{Q}=\frac{1}{\sqrt{2}}\begin{bmatrix}1&1\\1&-1\end{bmatrix}, \qquad \mathbf{R}=\begin{bmatrix}\sqrt{2}&2\sqrt{2}&0\\0&0&\sqrt{2}\end{bmatrix}. $$

The columns of \(\mathbf{Q}\) have norm \(1\) and dot product \(0\), so \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{I}_2\). Multiplication gives columns \(\sqrt{2}\mathbf{q}_1=(1,1)^{\top}\), \(2\sqrt{2}\mathbf{q}_1=(2,2)^{\top}\), and \(\sqrt{2}\mathbf{q}_2=(1,-1)^{\top}\). Therefore \(\mathbf{Q}\mathbf{R}=\mathbf{A}\), and the \(2\times3\) shape of \(\mathbf{R}\) is necessary because \(\mathbf{Q}\) is \(2\times2\).

Worked Example: A Zero First Column

Let the columns of \(\mathbf{A}\in\mathbb{R}^{3\times2}\) be \((0,0,0)^{\top}\) and \((1,2,0)^{\top}\). The first residual is zero, so there is no first column vector to normalize. The second column has norm \(\sqrt{5}\), giving \(\mathbf{q}_1=(1,2,0)^{\top}/\sqrt{5}\).

To complete the set, subtract the projection of \(\mathbf{e}_1\) onto \(\mathbf{q}_1\):

$$ \mathbf{e}_1-(\mathbf{q}_1\cdot\mathbf{e}_1)\mathbf{q}_1 = \begin{bmatrix}1\\0\\0\end{bmatrix} -\frac{1}{5}\begin{bmatrix}1\\2\\0\end{bmatrix} = \begin{bmatrix}4/5\\-2/5\\0\end{bmatrix}. $$

This residual has norm \(2/\sqrt{5}\), so \(\mathbf{q}_2=(2,-1,0)^{\top}/\sqrt{5}\). Take \(\mathbf{q}_3=\mathbf{e}_3\). The resulting factors are

$$ \mathbf{Q}=\begin{bmatrix} 1/\sqrt{5}&2/\sqrt{5}&0\\ 2/\sqrt{5}&-1/\sqrt{5}&0\\ 0&0&1 \end{bmatrix}, \qquad \mathbf{R}=\begin{bmatrix} 0&\sqrt{5}\\ 0&0\\ 0&0 \end{bmatrix}. $$

The columns of \(\mathbf{Q}\) have norm \(1\) and pairwise dot product \(0\), so \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{I}_3\). Multiplying \(\mathbf{Q}\) by the first column of \(\mathbf{R}\) gives \(\mathbf{0}\); multiplying by the second gives \(\sqrt{5}\mathbf{q}_1=(1,2,0)^{\top}\). Hence \(\mathbf{Q}\mathbf{R}=\mathbf{A}\).

Common Pitfall: Trying to Normalize Zero

For columns \(\mathbf{a}_1=(1,0)^{\top}\) and \(\mathbf{a}_2=(2,0)^{\top}\), Gram–Schmidt gives \(\mathbf{q}_1=(1,0)^{\top}\), then \(\mathbf{w}_2=\mathbf{a}_2-(\mathbf{q}_1\cdot\mathbf{a}_2)\mathbf{q}_1=(2,0)^{\top}-2(1,0)^{\top}=\mathbf{0}\). The wrong calculation is to set \(\mathbf{q}_2=\mathbf{w}_2/\|\mathbf{w}_2\|=\mathbf{0}/0\); division by zero is undefined. Skip this residual, and complete the set with \(\mathbf{e}_2\). Then \(\mathbf{Q}=\mathbf{I}_2\) and \(\mathbf{R}=\begin{bmatrix}1&2\\0&0\end{bmatrix}\). Direct multiplication gives \(\mathbf{Q}\mathbf{R}=\mathbf{A}\), and \(\mathbf{R}\) is upper triangular.

For a wide matrix, upper trapezoidal means entries below the main diagonal are zero wherever such entries exist; it does not mean that \(\mathbf{R}\) is square. Also, skipping a dependent column does not mean stopping the process: the wide example shows that a later column can contribute a new orthogonal direction. The full construction keeps these cases together by defining \(\mathbf{Q}\) to have one orthonormal column for each row of \(\mathbf{A}\), then recording every column’s coefficients in \(\mathbf{R}\).

Check Your Understanding

For each question, identify the dimensions and check any proposed factors by multiplication.

  1. In a full QR factorization of a \(4\times 2\) matrix, what are the dimensions of \(\mathbf{Q}\) and \(\mathbf{R}\)?
  2. Why must a zero Gram–Schmidt residual be skipped rather than normalized?
  3. For columns \((1,0)^{\top}\), \((0,1)^{\top}\), and \((1,1)^{\top}\), which column produces a zero residual when processed third?
  4. Explain why a vector added during completion is orthogonal to every column of \(\mathbf{A}\).
  5. For a \(3\times 5\) matrix, what does upper trapezoidal require of the entry \(r_{3,2}\)?

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon