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