Why Orthogonality Simplifies Least Squares
In a least-squares problem, the vector \(\mathbf{b}\) need not equal \(\mathbf{A}\mathbf{x}\) for any choice of \(\mathbf{x}\). Instead, we choose \(\mathbf{x}\) to make the residual \(\mathbf{b}-\mathbf{A}\mathbf{x}\) as short as possible. A QR factorization makes this minimization transparent: it separates the part of \(\mathbf{b}\) that can be represented by the columns of \(\mathbf{A}\) from the part that cannot.
Work over \(\mathbb{R}\). The norm is the Euclidean norm, so \(\|\mathbf{v}\|^2=\mathbf{v}^{\top}\mathbf{v}\), and two vectors are orthogonal when their dot product is zero. Suppose \(\mathbf{A}\in\mathbb{R}^{m\times n}\) has full column rank, with \(m\ge n\), and has a reduced QR factorization \(\mathbf{A}=\mathbf{Q}\mathbf{R}\). Here \(\mathbf{Q}\in\mathbb{R}^{m\times n}\) has orthonormal columns and \(\mathbf{R}\in\mathbb{R}^{n\times n}\) is nonsingular and upper triangular. Orthonormality means that the columns have length one and are pairwise orthogonal; in matrix form, \(\mathbf{Q}^{\top}\mathbf{Q}=\mathbf{I}_n\).
The columns of \(\mathbf{A}=\mathbf{Q}\mathbf{R}\) are combinations of the columns of \(\mathbf{Q}\). When \(\mathbf{R}\) is nonsingular, both matrices have the same column space. Thus the component of \(\mathbf{b}\) in \(\operatorname{Col}\mathbf{A}\) can be written using \(\mathbf{Q}\), while the leftover component is orthogonal to that space. The key is that changing \(\mathbf{x}\) changes only the first component; it cannot remove the orthogonal leftover.
The Orthogonal Decomposition Behind the QR Solve
For any \(\mathbf{b}\in\mathbb{R}^m\), define \(\mathbf{y}=\mathbf{Q}^{\top}\mathbf{b}\) and \(\mathbf{z}=\mathbf{b}-\mathbf{Q}\mathbf{y}\). Then \(\mathbf{b}=\mathbf{Q}\mathbf{y}+\mathbf{z}\). Moreover,
So \(\mathbf{z}\) is orthogonal to every column of \(\mathbf{Q}\), and hence to every vector in \(\operatorname{Col}\mathbf{Q}\). For any \(\mathbf{x}\), the residual can now be split into two orthogonal parts:
The second term lies in \(\operatorname{Col}\mathbf{Q}\); the first is orthogonal to that space. For orthogonal vectors \(\mathbf{u}\) and \(\mathbf{v}\), expanding the dot product gives \(\|\mathbf{u}+\mathbf{v}\|^2=\|\mathbf{u}\|^2+\|\mathbf{v}\|^2\), because the two cross terms are zero. Also, \(\|\mathbf{Q}\mathbf{c}\|^2=\mathbf{c}^{\top}\mathbf{Q}^{\top}\mathbf{Q}\mathbf{c}=\|\mathbf{c}\|^2\). Together these facts give the exact objective:
Proof. Put \(\mathbf{y}=\mathbf{Q}^{\top}\mathbf{b}\) and \(\mathbf{z}=\mathbf{b}-\mathbf{Q}\mathbf{y}\). The calculation above proves that \(\mathbf{z}\perp\operatorname{Col}\mathbf{Q}\) and that, for every \(\mathbf{x}\), \(\|\mathbf{b}-\mathbf{A}\mathbf{x}\|^2=\|\mathbf{z}\|^2+\|\mathbf{y}-\mathbf{R}\mathbf{x}\|^2\). The second summand is nonnegative, so the objective is at least \(\|\mathbf{z}\|^2\). Since \(\mathbf{R}\) is nonsingular, the system \(\mathbf{R}\widehat{\mathbf{x}}=\mathbf{y}\) has exactly one solution. At that solution the second summand is zero, so the lower bound is attained. Any minimizer must make that summand zero, which forces \(\mathbf{R}\mathbf{x}=\mathbf{y}\), and thus must equal \(\widehat{\mathbf{x}}\). The residual there is \(\mathbf{z}=\mathbf{b}-\mathbf{Q}\mathbf{Q}^{\top}\mathbf{b}\). \(\square\)
Because \(\mathbf{R}\) is upper triangular, the equation can be solved by back substitution, starting from its last row. The QR argument does not claim that the original equations \(\mathbf{A}\mathbf{x}=\mathbf{b}\) have an exact solution. It proves instead that matching the \(\mathbf{Q}\)-coordinates of \(\mathbf{b}\) removes every part of the residual that lies in the column space, leaving only the orthogonal component.
Worked QR Least-Squares Calculations
Worked Example: A Full-Rank Triangular Solve
Let
The columns of \(\mathbf{Q}\) are orthonormal, and multiplying gives
Compute the right-hand side of the triangular system:
Now solve \(\mathbf{R}\mathbf{x}=\mathbf{Q}^{\top}\mathbf{b}\). The second row gives \(3x_2=6\), so \(x_2=2\). The first row gives \(2x_1+x_2=5\), so \(2x_1+2=5\) and \(x_1=\tfrac32\). Therefore \(\widehat{\mathbf{x}}=(\tfrac32,2)^{\top}\). Check the multiplication:
The residual is orthogonal to both columns of \(\mathbf{A}\), and its squared norm is \(16\). Also, \(\mathbf{b}-\mathbf{Q}\mathbf{Q}^{\top}\mathbf{b}=(0,0,4)^{\top}\), agreeing with the residual predicted by the theorem.
Worked Example: An Orthonormal Basis Not Made of Standard Coordinate Vectors
Take the columns of \(\mathbf{Q}\) to be \(\mathbf{q}_1=(1,1,0,0)^{\top}/\sqrt{2}\) and \(\mathbf{q}_2=(0,0,1,1)^{\top}/\sqrt{2}\), and let \(\mathbf{R}=\begin{bmatrix}2&1\\0&1\end{bmatrix}\). The columns of \(\mathbf{Q}\) each have squared length \(1\), and their dot product is \(0\). Choose \(\mathbf{b}=3\mathbf{q}_1+2\mathbf{q}_2+(1,-1,0,0)^{\top}\). The last vector is orthogonal to both columns of \(\mathbf{Q}\). In coordinates,
Since the added vector is orthogonal to the columns, \(\mathbf{Q}^{\top}\mathbf{b}=(3,2)^{\top}\). Solve the triangular system: the second row gives \(x_2=2\), and the first gives \(2x_1+x_2=3\), hence \(x_1=\tfrac12\). Thus \(\widehat{\mathbf{x}}=(\tfrac12,2)^{\top}\). To check, \(\mathbf{R}\widehat{\mathbf{x}}=(3,2)^{\top}\), so \(\mathbf{A}\widehat{\mathbf{x}}=\mathbf{Q}(3,2)^{\top}=3\mathbf{q}_1+2\mathbf{q}_2\). Subtracting from \(\mathbf{b}\) leaves \((1,-1,0,0)^{\top}\), whose dot products with \(\mathbf{q}_1,\mathbf{q}_2\) are both zero. This verifies both the solve and the residual decomposition.
What Changes When the Columns Are Dependent?
A rank-deficient matrix cannot have a nonsingular square \(\mathbf{R}\) in a reduced factorization with \(n\) columns in \(\mathbf{Q}\). A rank-\(r\) factorization instead has \(\mathbf{Q}\in\mathbb{R}^{m\times r}\) with orthonormal columns and \(\mathbf{R}\in\mathbb{R}^{r\times n}\). In this case \(\mathbf{R}\) has full row rank, but may have more columns than rows. The same orthogonal decomposition proves that the least-squares minimizers are exactly the solutions of \(\mathbf{R}\mathbf{x}=\mathbf{Q}^{\top}\mathbf{b}\); the system may have multiple solutions rather than one triangular back-substitution solution.
Proof. Set \(\mathbf{y}=\mathbf{Q}^{\top}\mathbf{b}\) and \(\mathbf{z}=\mathbf{b}-\mathbf{Q}\mathbf{y}\). As before, \(\mathbf{Q}^{\top}\mathbf{z}=\mathbf{0}\), and for every \(\mathbf{x}\), \(\mathbf{b}-\mathbf{A}\mathbf{x}=\mathbf{z}+\mathbf{Q}(\mathbf{y}-\mathbf{R}\mathbf{x})\), a sum of orthogonal vectors. Therefore the squared residual norm is \(\|\mathbf{z}\|^2+\|\mathbf{y}-\mathbf{R}\mathbf{x}\|^2\). Full row rank means that the columns of \(\mathbf{R}\) span \(\mathbb{R}^r\), so the equation \(\mathbf{R}\mathbf{x}=\mathbf{y}\) has a solution. Every solution attains the lower bound \(\|\mathbf{z}\|^2\), and any minimizer must attain that bound, forcing \(\mathbf{R}\mathbf{x}=\mathbf{y}\). \(\square\)
Worked Example: A Rank-Deficient QR Factorization
Let \(\mathbf{q}=(1,0,1)^{\top}/\sqrt{2}\), \(\mathbf{Q}=\mathbf{q}\), \(\mathbf{R}=\begin{bmatrix}2&4\end{bmatrix}\), and \(\mathbf{b}=(3,5,1)^{\top}\). Then \(\mathbf{A}=\mathbf{Q}\mathbf{R}=\begin{bmatrix}\sqrt{2}&2\sqrt{2}\\0&0\\\sqrt{2}&2\sqrt{2}\end{bmatrix}\), whose second column is twice its first. The right-hand side for the reduced system is
The equation \(2x_1+4x_2=2\sqrt{2}\) has many solutions. For example, choose \(x_1=\sqrt{2}\), \(x_2=0\). Then \(\mathbf{A}\mathbf{x}=(2,0,2)^{\top}\), and the residual is \((1,5,-1)^{\top}\). Its dot product with \(\mathbf{q}\) is \((1-1)/\sqrt{2}=0\), so it is orthogonal to \(\operatorname{Col}\mathbf{A}\). The minimum squared residual is \(1^2+5^2+(-1)^2=27\). The other solutions to the reduced equation also give the same fitted vector and residual.
Common Mistake: Requiring an Exact Fit
In the first worked example, a tempting but incorrect step is to solve \(\mathbf{A}\mathbf{x}=\mathbf{b}\) and conclude that the least-squares problem has no solution because the third row says \(0=4\). That calculation only proves that no exact fit exists. It does not rule out a vector that minimizes the residual. The QR calculation gives \(\widehat{\mathbf{x}}=(\tfrac32,2)^{\top}\), with residual \((0,0,4)^{\top}\); every other choice adds a nonzero component in the column space to this orthogonal residual, increasing the squared norm.
Another error is to replace \(\mathbf{Q}^{\top}\mathbf{b}\) with \(\mathbf{Q}\mathbf{b}\). The matrix \(\mathbf{Q}\) is generally rectangular, so \(\mathbf{Q}\mathbf{b}\) may not even be defined. The coordinate vector in the orthonormal columns is \(\mathbf{Q}^{\top}\mathbf{b}\); the corresponding vector in the original space is \(\mathbf{Q}\mathbf{Q}^{\top}\mathbf{b}\). Keeping those two roles separate makes the decomposition and dimensions consistent.
Check Your Understanding
Use the orthogonal decomposition, not an assumption that \(\mathbf{A}\mathbf{x}=\mathbf{b}\) has an exact solution.
- For a reduced QR factorization with full column rank, explain why \(\mathbf{b}-\mathbf{Q}\mathbf{Q}^{\top}\mathbf{b}\) is orthogonal to every column of \(\mathbf{Q}\).
- Let \(\mathbf{Q}=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}\), \(\mathbf{R}=\begin{bmatrix}1&2\\0&1\end{bmatrix}\), and \(\mathbf{b}=(4,3,5)^{\top}\). Solve the triangular system and compute the residual.
- Why does nonsingularity of \(\mathbf{R}\) guarantee that the full-column-rank QR least-squares solution is unique?
- In rank-deficient QR, what condition must \(\mathbf{x}\) satisfy to be a least-squares minimizer?
- Explain why solving the least-squares problem is not the same as requiring \(\mathbf{A}\mathbf{x}=\mathbf{b}\).