Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Find an Orthogonal Projection

The orthogonal projection of y\mathbf{y} onto a subspace WW is the point of WW closest to y\mathbf{y}. With an orthogonal basis it is a sum of one-line projections, and the leftover y−y^\mathbf{y} - \hat{\mathbf{y}} is perpendicular to WW.

Recognize the task

The problem asks for proj⁡Wy\operatorname{proj}_W \mathbf{y}, the closest point on a line or plane, the distance from a point to a subspace, or a split y=y^+z\mathbf{y} = \hat{\mathbf{y}} + \mathbf{z}. Forms: onto the line through (1,1)(1, 1), onto the plane x+y+z=0x + y + z = 0, onto Span⁡{(1,1,0),(1,−1,1)}\operatorname{Span}\{(1, 1, 0), (1, -1, 1)\}. Test: is the basis of WW orthogonal? That decides the method.
Projections are defined in the projections lesson; the split itself is the orthogonal decomposition.

Ways to do it

Onto a lineone vector
proj⁡ay=y⋅aa⋅a a\operatorname{proj}_{\mathbf{a}} \mathbf{y} = \frac{\mathbf{y} \cdot \mathbf{a}}{\mathbf{a} \cdot \mathbf{a}}\,\mathbf{a}
One ratio of dot products (projection onto a line), as in the vector projection method.
Orthogonal basissubspace, orthogonal basis
y^=y⋅u1u1⋅u1u1+⋯+y⋅ukuk⋅ukuk\hat{\mathbf{y}} = \frac{\mathbf{y} \cdot \mathbf{u}_1}{\mathbf{u}_1 \cdot \mathbf{u}_1}\mathbf{u}_1 + \cdots + \frac{\mathbf{y} \cdot \mathbf{u}_k}{\mathbf{u}_k \cdot \mathbf{u}_k}\mathbf{u}_k
Add one line projection per basis vector (projection onto a subspace).
Any basisbasis not orthogonal
y^=Ax^,ATA x^=ATy\hat{\mathbf{y}} = A\hat{\mathbf{x}}, \quad A^TA\,\hat{\mathbf{x}} = A^T\mathbf{y}
Put the basis in the columns of AA and solve the normal equations, or run Gram-Schmidt first.

Steps

StepOn y=(2,3,4)\mathbf{y} = (2, 3, 4), W=Span⁡{(1,1,0),(1,−1,1)}W = \operatorname{Span}\{(1, 1, 0), (1, -1, 1)\}
1Check that the basis is orthogonal. If u1⋅u2≠0\mathbf{u}_1 \cdot \mathbf{u}_2 \neq 0, switch to the normal equations or orthogonalize first.u1⋅u2=1−1+0=0\mathbf{u}_1 \cdot \mathbf{u}_2 = 1 - 1 + 0 = 0 ✓
2Compute one coefficient per basis vector. Each coefficient is y⋅uiui⋅ui\frac{\mathbf{y} \cdot \mathbf{u}_i}{\mathbf{u}_i \cdot \mathbf{u}_i}.2+3+02=52\frac{2 + 3 + 0}{2} = \frac{5}{2} and 2−3+43=1\frac{2 - 3 + 4}{3} = 1
3Add the scaled basis vectors. The sum is the projection y^\hat{\mathbf{y}}, a point of WW.y^=52(1,1,0)+(1,−1,1)=(72,32,1)\hat{\mathbf{y}} = \frac{5}{2}(1, 1, 0) + (1, -1, 1) = (\frac{7}{2}, \frac{3}{2}, 1)
4Check the residual. The leftover z=y−y^\mathbf{z} = \mathbf{y} - \hat{\mathbf{y}} must be orthogonal to every basis vector. Its length is the distance from y\mathbf{y} to WW.z=(−32,32,3)\mathbf{z} = (-\frac{3}{2}, \frac{3}{2}, 3), z⋅u1=z⋅u2=0\mathbf{z} \cdot \mathbf{u}_1 = \mathbf{z} \cdot \mathbf{u}_2 = 0, distance 362\frac{3\sqrt{6}}{2}

Worked examples

Example 1 · onto a line

one vector
y=(1,3)\mathbf{y} = (1, 3), a=(1,1)\mathbf{a} = (1, 1): y⋅aa⋅a=42=2\frac{\mathbf{y} \cdot \mathbf{a}}{\mathbf{a} \cdot \mathbf{a}} = \frac{4}{2} = 2
ratio of dot products
proj⁡ay=(2,2)\operatorname{proj}_{\mathbf{a}}\mathbf{y} = (2, 2), residual (−1,1)(-1, 1)
residual is perpendicular to a\mathbf{a}

Example 2 · onto a plane through its normal

remove the normal part
y=(1,2,6)\mathbf{y} = (1, 2, 6), plane x+y+z=0x + y + z = 0, n=(1,1,1)\mathbf{n} = (1, 1, 1)
normal from the coefficients
y⋅nn⋅n=93=3\frac{\mathbf{y} \cdot \mathbf{n}}{\mathbf{n} \cdot \mathbf{n}} = \frac{9}{3} = 3
the part along the normal
y^=(1,2,6)−3(1,1,1)=(−2,−1,3)\hat{\mathbf{y}} = (1, 2, 6) - 3(1, 1, 1) = (-2, -1, 3)
entries add to 00: in the plane
This is the projection onto a plane formula.

Example 3 · a basis that is not orthogonal

normal equations
W=Span⁡{(1,0,1),(1,1,0)}W = \operatorname{Span}\{(1, 0, 1), (1, 1, 0)\}, y=(3,2,4)\mathbf{y} = (3, 2, 4)
the basis vectors have dot product 11
ATA=(2112)A^TA = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}, ATy=(7,5)A^T\mathbf{y} = (7, 5)
the basis forms the columns of AA
x^=(3,1)\hat{\mathbf{x}} = (3, 1)
solve the 2×22 \times 2 system
y^=3(1,0,1)+(1,1,0)=(4,1,3)\hat{\mathbf{y}} = 3(1, 0, 1) + (1, 1, 0) = (4, 1, 3)
residual (−1,1,1)(-1, 1, 1) is perpendicular

See it happen

Drop a perpendicular from the tip of y\mathbf{y} to the subspace: where it lands is y^\hat{\mathbf{y}}, and the perpendicular itself is z\mathbf{z}. No other point of WW is closer, because moving away from y^\hat{\mathbf{y}} inside WW adds a sideways piece at a right angle to z\mathbf{z}, and by Pythagoras that only makes the distance longer. Drag the vectors in the projection 2D visualizer.

Common mistakes

Adding projections onto a basis that is not orthogonal

✗ for (1,0,1)(1, 0, 1), (1,1,0)(1, 1, 0) and y=(3,2,4)\mathbf{y} = (3, 2, 4): 72(1,0,1)+52(1,1,0)=(6,52,72)\frac{7}{2}(1, 0, 1) + \frac{5}{2}(1, 1, 0) = (6, \frac{5}{2}, \frac{7}{2})
✓ the basis is not orthogonal: solve the normal equations, y^=(4,1,3)\hat{\mathbf{y}} = (4, 1, 3)

Dividing by the length, not the squared length

✗ y⋅a∥a∥ a=42(1,1)\frac{\mathbf{y} \cdot \mathbf{a}}{\|\mathbf{a}\|}\,\mathbf{a} = \frac{4}{\sqrt{2}}(1, 1)
✓ y⋅aa⋅a a=2(1,1)\frac{\mathbf{y} \cdot \mathbf{a}}{\mathbf{a} \cdot \mathbf{a}}\,\mathbf{a} = 2(1, 1)
The scalar projection divides by ∥a∥\|\mathbf{a}\|; the vector projection divides by ∥a∥2\|\mathbf{a}\|^2.

Reporting the normal part as the projection

✗ onto the plane x+y+z=0x + y + z = 0: y^=3(1,1,1)\hat{\mathbf{y}} = 3(1, 1, 1)
✓ that is the part along the normal; y^=y−3(1,1,1)=(−2,−1,3)\hat{\mathbf{y}} = \mathbf{y} - 3(1, 1, 1) = (-2, -1, 3)