Projections onto
Lines & Subspaces
Learn how to project vectors onto lines and subspaces: the geometric idea, the formula, and the projection matrix.
What Is a Projection?
Imagine shining a flashlight straight down onto a line. The shadow your vector casts on that line is its projection. Formally, the projection of \(\mathbf{b}\) onto a line through \(\mathbf{a}\) is the closest point on that line to \(\mathbf{b}\).
Why Do Projections Matter?
The Key Idea: Orthogonality
The projection \(\text{proj}_{\mathbf{a}}\,\mathbf{b}\) is the point on the line through \(\mathbf{a}\) such that the error vector is orthogonal to \(\mathbf{a}\). If \(\hat{\mathbf{p}} = \hat{x}\,\mathbf{a}\), then:
This single equation captures the whole idea: set the error perpendicular to the direction of projection, then solve for the scalar \(\hat{x}\).
Projection onto a Line
The Projection Matrix
We can rewrite the formula as a matrix times \(\mathbf{b}\):
Projection onto a Subspace
When the target is a subspace spanned by the columns of \(A\) (not just one vector), the same orthogonality idea applies. The error \(\mathbf{b} - A\hat{\mathbf{x}}\) must be perpendicular to every column of \(A\):
This generalises the line formula. When \(A\) is a single column vector \(\mathbf{a}\), it reduces back to \(\frac{\mathbf{a}\mathbf{a}^T}{\mathbf{a}^T\mathbf{a}}\).
Line vs Subspace Projection
| Onto a Line | Onto a Subspace | |
|---|---|---|
| Target | Line through \(\mathbf{a}\) | Col space of \(A\) |
| Scalar | \(\hat{x} = \frac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}}\) | \(\hat{\mathbf{x}} = (A^TA)^{-1}A^T\mathbf{b}\) |
| Proj Matrix | \(\frac{\mathbf{a}\mathbf{a}^T}{\mathbf{a}^T\mathbf{a}}\) | \(A(A^TA)^{-1}A^T\) |
| Rank of \(P\) | 1 | \(\text{rank}(A)\) |
| Properties | \(P^2=P,\; P^T=P\) | \(P^2=P,\; P^T=P\) |
How to Compute a Projection
Example 1: Projection onto a Line
Project \(\mathbf{b} = \begin{pmatrix}1\\2\\2\end{pmatrix}\) onto the line through \(\mathbf{a} = \begin{pmatrix}1\\0\\1\end{pmatrix}\).
Example 2: Projection Matrix
Find the projection matrix \(P\) that projects onto the line through \(\mathbf{a} = \begin{pmatrix}2\\1\end{pmatrix}\).
Example 3: Onto a Plane
Project \(\mathbf{b}=\begin{pmatrix}1\\1\\1\end{pmatrix}\) onto the column space of \(A=\begin{pmatrix}1&0\\0&1\\0&0\end{pmatrix}\).
Visualising Subspace Projection
Properties of \(P\)
Common Mistakes
Summary Cheat Sheet
| Quantity | Formula | Notes |
|---|---|---|
| Proj onto line | \(\frac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}}\,\mathbf{a}\) | Scalar times vector |
| \(P\) (line) | \(\frac{\mathbf{a}\mathbf{a}^T}{\mathbf{a}^T\mathbf{a}}\) | Rank 1, symmetric |
| Normal eq. | \(A^TA\hat{\mathbf{x}} = A^T\mathbf{b}\) | Key equation |
| \(P\) (subspace) | \(A(A^TA)^{-1}A^T\) | Rank = rank(\(A\)) |
| Error | \(\mathbf{e}=\mathbf{b}-P\mathbf{b}\) | \(\mathbf{e}\perp\) col(\(A\)) |
Question 1 of 5
What is the projection of \(\mathbf{b}=\begin{pmatrix}3\\4\end{pmatrix}\) onto the line through \(\mathbf{a}=\begin{pmatrix}1\\0\end{pmatrix}\)?
Question 2 of 5
If \(P\) is a projection matrix, which property must it satisfy?
Question 3 of 5
The error vector \(\mathbf{e} = \mathbf{b} - \text{proj}_{\mathbf{a}}\,\mathbf{b}\) is always:
Question 4 of 5
What is the projection matrix \(P\) that projects onto the line through \(\mathbf{a}=\begin{pmatrix}1\\1\end{pmatrix}\)?
Question 5 of 5
For the subspace formula \(P = A(A^TA)^{-1}A^T\), what does \((A^TA)^{-1}\) require?