Projection onto a Subspace

April 13, 2026

Problem

Project b = [1, 2, 3] onto the column space of A = [[1, 0],[0, 1],[0, 0]]. Show the projection and the residual.

Explanation

Projection — the idea

Given a vector b\mathbf{b} and a subspace VV, the orthogonal projection of b\mathbf{b} onto VV, written projV(b)\operatorname{proj}_V(\mathbf{b}), is the unique vector pV\mathbf{p} \in V closest to b\mathbf{b}. The residual r=bp\mathbf{r} = \mathbf{b} - \mathbf{p} is orthogonal to every vector in VV.

Decomposition: b=pV+rV\mathbf{b} = \underbrace{\mathbf{p}}_{\in V} + \underbrace{\mathbf{r}}_{\in V^\perp}

This split is unique.

Projection formula via a matrix AA

If V=Col(A)V = \operatorname{Col}(A) where AA's columns are linearly independent, then projV(b)=A(ATA)1ATb\operatorname{proj}_V(\mathbf{b}) = A (A^T A)^{-1} A^T \, \mathbf{b}

The matrix P=A(ATA)1ATP = A (A^T A)^{-1} A^T is the projection matrix.

Properties of any projection matrix:

  • P2=PP^2 = P (applying twice is the same as once — idempotent).
  • PT=PP^T = P (symmetric — for orthogonal projection).
  • Eigenvalues are 0 (in VV^\perp) or 1 (in VV).

Step-by-step

A=(100100),b=(123)A = \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{pmatrix}, \quad \mathbf{b} = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix}

V=Col(A)V = \operatorname{Col}(A) is the xyxy-plane in R3\mathbb{R}^3 — the set of all vectors with last coordinate zero.

Step 1 — ATAA^T A. ATA=(100010)(100100)=(1001)=I2A^T A = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I_2

Since ATA=IA^T A = I, (ATA)1=I(A^T A)^{-1} = I.

Step 2 — ATbA^T \mathbf{b}. ATb=(100010)(123)=(12)A^T \mathbf{b} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \end{pmatrix} \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} = \begin{pmatrix} 1 \\ 2 \end{pmatrix}

Step 3 — Projection. p=A(12)=(120)\mathbf{p} = A \cdot \begin{pmatrix} 1 \\ 2 \end{pmatrix} = \begin{pmatrix} 1 \\ 2 \\ 0 \end{pmatrix}

Step 4 — Residual. r=bp=(123)(120)=(003)\mathbf{r} = \mathbf{b} - \mathbf{p} = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} - \begin{pmatrix} 1 \\ 2 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 3 \end{pmatrix}

Check rV\mathbf{r} \perp V: the plane VV is spanned by e1,e2\mathbf{e}_1, \mathbf{e}_2. re1=0\mathbf{r} \cdot \mathbf{e}_1 = 0, re2=0\mathbf{r} \cdot \mathbf{e}_2 = 0

Visual interpretation

b=(1,2,3)\mathbf{b} = (1, 2, 3) is a vector in R3\mathbb{R}^3. The plane VV is the floor (xyxy-plane). The projection p\mathbf{p} is the shadow of b\mathbf{b} directly below it — (1,2,0)(1, 2, 0) on the floor. The residual (0,0,3)(0, 0, 3) is the straight-up vertical piece.

Projection onto a line

For VV spanned by a single non-zero vector a\mathbf{a}, the formula simplifies dramatically: proja(b)=abaaa\operatorname{proj}_\mathbf{a}(\mathbf{b}) = \dfrac{\mathbf{a} \cdot \mathbf{b}}{\mathbf{a} \cdot \mathbf{a}} \, \mathbf{a}

This is the scalar "coefficient of a\mathbf{a} in b\mathbf{b}" times a\mathbf{a} itself. It's the 1-column case of the general formula above.

Where projections appear

  • Least squares regression: the fitted values are the projection of y\mathbf{y} onto the column space of the design matrix.
  • PCA: project data onto principal components.
  • Orthogonal decompositions: separating a signal into parts (low-frequency + high-frequency).
  • Image compression: project onto a few top basis vectors and discard the rest.
  • Fourier series: coefficients are projections of f(x)f(x) onto basis functions.

Best approximation property

Among all vectors vV\mathbf{v} \in V, p=projV(b)\mathbf{p} = \operatorname{proj}_V(\mathbf{b}) minimizes bv\|\mathbf{b} - \mathbf{v}\|. That's why projection is the foundation of least-squares approximation — it provides the closest point in a subspace.

Common mistakes

  • Using the wrong columns. Only use columns that are linearly independent; otherwise ATAA^T A is singular.
  • Forgetting that projection is idempotent. Applying PP twice gives the same result as once; P(Pb)=PbP(P \mathbf{b}) = P \mathbf{b}.
  • Confusing orthogonal projection with oblique projection. Oblique projections exist (P2=PP^2 = P but not symmetric); our formula produces orthogonal ones.

Try it in the visualization

b\mathbf{b} and the subspace VV are drawn in 3D. A vertical dashed line from b\mathbf{b} to the subspace shows the projection path. The projected vector p\mathbf{p} sits on the plane; the residual r\mathbf{r} points perpendicular.

Interactive Visualization

Parameters

1.00
2.00
3.00
xy-plane (cols [[1,0],[0,1],[0,0]])
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Projection onto a Subspace | MathSpin