Recipe
Solve a least-squares problem from an existing QR factorization
Use when: you already have A=QR (orthonormal Q, upper-triangular R) and need the least-squares solution to A\mathbf x\approx\mathbf b
Goal: \hat{\mathbf x}, found with one matrix-vector product and one back substitution — no matrix ever multiplied by its own transpose
Taught in Least squares by QR
Quick recipe
-
1
Dot each column of Q with \mathbf b.
Example
For Q=\begin{bmatrix}\tfrac23&-\tfrac23\\\tfrac13&\tfrac23\\\tfrac23&\tfrac13\end{bmatrix} and \mathbf b=(5,-2,5): \mathbf q_1\cdot\mathbf b=\tfrac23(5)+\tfrac13(-2)+\tfrac23(5)=\tfrac{10}{3}-\tfrac23+\tfrac{10}{3}=6, and \mathbf q_2\cdot\mathbf b=-\tfrac23(5)+\tfrac23(-2)+\tfrac13(5)=-\tfrac{10}{3}-\tfrac43+\tfrac53=-3. So Q^{\mathsf T}\mathbf b=(6,-3).
Why: this single matrix-vector product carries every bit of \mathbf b's information the least-squares solve actually needs — no A^{\mathsf T}A required anywhere.
-
2
The last row of R has only one nonzero entry, so it already isolates one unknown.
Example
With R=\begin{bmatrix}3&3\\0&3\end{bmatrix} and Q^{\mathsf T}\mathbf b=(6,-3): the bottom row reads 3\hat x_2=-3, so \hat x_2=-1.
Why: R is upper triangular by construction — QR factoring was built column by column precisely so the last row would come out this simple.
-
3
Plug the values already found into the next row up, solve for its one remaining unknown, and repeat until every entry of \hat{\mathbf x} is known.
Example
The top row reads 3\hat x_1+3\hat x_2=6, so 3\hat x_1+3(-1)=6\implies 3\hat x_1=9\implies\hat x_1=3. So \hat{\mathbf x}=(3,-1).
Why: triangularity guarantees each row above the bottom introduces exactly one new unknown once you work upward — the same reason back substitution works on any triangular system.
-
4
Multiply A by the \hat{\mathbf x} you found; it should equal \mathbf b exactly only if the original system happened to be consistent, and otherwise land as close to \mathbf b as \operatorname{col}(A) allows.
Example
A=\begin{bmatrix}2&0\\1&3\\2&3\end{bmatrix}: A\hat{\mathbf x}=\begin{pmatrix}2(3)+0(-1)\\1(3)+3(-1)\\2(3)+3(-1)\end{pmatrix}=\begin{pmatrix}6\\0\\3\end{pmatrix}, while \mathbf b=(5,-2,5) — a leftover residual of (-1,-2,2), since \mathbf b wasn't exactly in \operatorname{col}(A).
Why: this is the same sanity check the normal-equations route uses, just arrived at without ever forming A^{\mathsf T}A — a large or oddly-shaped residual usually means an earlier row or dot product was computed wrong.
Common mistakes
- Forming A^{\mathsf T}A out of habit anyway — the entire point of this route is skipping that multiplication.
- Using A^{\mathsf T}\mathbf b in place of Q^{\mathsf T}\mathbf b — the two are not the same vector, only the two routes' final \hat{\mathbf x} agree.
- Starting back substitution from the top row instead of the bottom — only the bottom row of R is guaranteed to have just one unknown.
- Forgetting that \hat{\mathbf x}'s entries correspond to R's columns in order, and reporting them in the wrong order.