Skip to main content
© 2026 ePowerAI. All rights reserved.
CoursesContact
eAI
CoursesContact
Week 7: Orthogonality and Projections
Linear Algebra
01Week 1: Vectors and Linear Combinations
02Week 2: Linear Transformations and Matrices
03Week 3: Elimination and LU Factorization
04Week 4: Determinants
05Week 5: Vector Spaces, Independence, and Basis
06Week 6: The Four Fundamental Subspaces
07Week 7: Orthogonality and Projections
08Week 8: Least Squares and QR
09Week 9: Eigenvalues and Eigenvectors
10Week 10: Diagonalization and Markov Matrices
11Week 11: Differential Equations
12Week 12: Symmetric and Positive Definite Matrices
13Week 13: The SVD and Complex Matrices
14Week 14: The Fourier Matrix, FFT, and PCA
Week 07· Linear Algebra18 min read

Week 7: Orthogonality and Projections

✦Learning Outcomes
  • Determine when vectors or subspaces are orthogonal
  • Compute the projection of a vector onto a line and onto a subspace
  • Construct the projection matrix for a given subspace
  • Explain the connection between orthogonality and the four fundamental subspaces
◆Prerequisites

Background knowledge assumed:

  • The dot product
  • The four fundamental subspaces

Recommended: Review Week 1: Vectors and Linear Combinations and Week 6: The Four Fundamental Subspaces before starting.

Orthogonal Vectors and Subspaces#

Week 1 defined the dot product of two vectors u,v∈Rnu, v \in \mathbb{R}^nu,v∈Rn as

u⊤v=u1v1+⋯+unvn.u^\top v = u_1 v_1 + \cdots + u_n v_n.u⊤v=u1​v1​+⋯+un​vn​.

Two vectors are orthogonal when their dot product is zero:

u⊥v⟺u⊤v=0.u \perp v \quad\Longleftrightarrow\quad u^\top v = 0.u⊥v⟺u⊤v=0.

Geometrically, orthogonal vectors meet at a right angle. Algebraically, the test is a single number. The zero vector is orthogonal to every vector, because 0⊤v=00^\top v = 00⊤v=0 always.

Orthogonal subspaces. Two subspaces V,W⊆RnV, W \subseteq \mathbb{R}^nV,W⊆Rn are orthogonal when every vector in one is orthogonal to every vector in the other:

V⊥W⟺v⊤w=0 for all v∈V,  w∈W.V \perp W \quad\Longleftrightarrow\quad v^\top w = 0 \text{ for all } v \in V,\; w \in W.V⊥W⟺v⊤w=0 for all v∈V,w∈W.

It is enough to check bases: if every basis vector of VVV is orthogonal to every basis vector of WWW, the whole subspaces are orthogonal (by bilinearity of the dot product).

Orthogonal complements and the four subspaces. Week 6 introduced the four fundamental subspaces of an m×nm \times nm×n matrix AAA. Orthogonality locks them into complementary pairs:

  • In Rn\mathbb{R}^nRn: the row space C(A⊤)C(A^\top)C(A⊤) and the null space N(A)N(A)N(A) are orthogonal complements. Every row of AAA is orthogonal to every xxx with Ax=0Ax = 0Ax=0 (because Ax=0Ax = 0Ax=0 means each row dotted with xxx is zero). Dimensions add: dim⁡C(A⊤)+dim⁡N(A)=r+(n−r)=n\dim C(A^\top) + \dim N(A) = r + (n - r) = ndimC(A⊤)+dimN(A)=r+(n−r)=n, so together they fill all of Rn\mathbb{R}^nRn.
  • In Rm\mathbb{R}^mRm: the column space C(A)C(A)C(A) and the left null space N(A⊤)N(A^\top)N(A⊤) are orthogonal complements. If A⊤y=0A^\top y = 0A⊤y=0, then yyy is orthogonal to every column of AAA. Dimensions add: r+(m−r)=mr + (m - r) = mr+(m−r)=m.

We write N(A)=C(A⊤)⊥N(A) = C(A^\top)^\perpN(A)=C(A⊤)⊥ and N(A⊤)=C(A)⊥N(A^\top) = C(A)^\perpN(A⊤)=C(A)⊥. That is the structural fact Week 6 previewed: the kernel of AAA is exactly the orthogonal complement of the row space, and the left null space is the orthogonal complement of the column space.

Why this matters for projections. Any vector b∈Rmb \in \mathbb{R}^mb∈Rm decomposes uniquely as

b=p+e,p∈C(A),e∈N(A⊤),b = p + e, \qquad p \in C(A),\quad e \in N(A^\top),b=p+e,p∈C(A),e∈N(A⊤),

with p⊥ep \perp ep⊥e. The piece ppp is the orthogonal projection of bbb onto the column space — the closest point of C(A)C(A)C(A) to bbb. The rest of this week builds the formulas that produce ppp.


Projection onto a Line#

Start with the simplest subspace: a line through the origin spanned by a nonzero vector a∈Rna \in \mathbb{R}^na∈Rn. Given a vector bbb, we want the point ppp on that line closest to bbb. Write

p=x^ ap = \hat{x}\, ap=x^a

for some scalar x^\hat{x}x^. The error (residual) is e=b−p=b−x^ ae = b - p = b - \hat{x}\, ae=b−p=b−x^a. For ppp to be the orthogonal projection, the error must be orthogonal to the line — that is, orthogonal to aaa:

a⊤(b−x^ a)=0.a^\top (b - \hat{x}\, a) = 0.a⊤(b−x^a)=0.

Expand and solve for x^\hat{x}x^:

a⊤b−x^ (a⊤a)=0⟹x^=a⊤ba⊤a.a^\top b - \hat{x}\, (a^\top a) = 0 \quad\Longrightarrow\quad \hat{x} = \frac{a^\top b}{a^\top a}.a⊤b−x^(a⊤a)=0⟹x^=a⊤aa⊤b​.

Therefore the projection is

p=a⊤ba⊤a a.p = \frac{a^\top b}{a^\top a}\, a.p=a⊤aa⊤b​a.

Geometric reading. The scalar x^\hat{x}x^ is the coordinate of bbb along the unit direction of aaa, scaled by ∥a∥\|a\|∥a∥. The formula never needs an explicit unit vector: the factor 1/(a⊤a)1/(a^\top a)1/(a⊤a) absorbs the length of aaa.

Worked example. Project b=(42)b = \begin{pmatrix} 4 \\ 2 \end{pmatrix}b=(42​) onto the line spanned by a=(11)a = \begin{pmatrix} 1 \\ 1 \end{pmatrix}a=(11​).

a⊤b=4+2=6,a⊤a=1+1=2,x^=62=3.a^\top b = 4 + 2 = 6, \qquad a^\top a = 1 + 1 = 2, \qquad \hat{x} = \frac{6}{2} = 3.a⊤b=4+2=6,a⊤a=1+1=2,x^=26​=3.

So

p=3(11)=(33).p = 3\begin{pmatrix} 1 \\ 1 \end{pmatrix} = \begin{pmatrix} 3 \\ 3 \end{pmatrix}.p=3(11​)=(33​).

The error is e=b−p=(1−1)e = b - p = \begin{pmatrix} 1 \\ -1 \end{pmatrix}e=b−p=(1−1​), and a⊤e=1−1=0a^\top e = 1 - 1 = 0a⊤e=1−1=0 — orthogonal, as required. Notice ∥e∥2=2\|e\|^2 = 2∥e∥2=2 is the squared distance from bbb to the line; any other point on the line would be farther.

Special cases.

  • If bbb already lies on the line, then b=cab = cab=ca for some ccc, and x^=c\hat{x} = cx^=c, so p=bp = bp=b.
  • If b⊥ab \perp ab⊥a, then a⊤b=0a^\top b = 0a⊤b=0 and p=0p = 0p=0 — the nearest point on the line is the origin.
Exercise · Fill in the blank

Project b = (4, 2) onto the line spanned by a = (1, 1). What is the x-coordinate of the projection?


Projection onto a Subspace#

Now replace the line span⁡{a}\operatorname{span}\{a\}span{a} by a higher-dimensional subspace. Let the columns of an m×nm \times nm×n matrix AAA form a basis for the subspace we project onto (so AAA has full column rank nnn, and the subspace is C(A)⊆RmC(A) \subseteq \mathbb{R}^mC(A)⊆Rm). Any point in the subspace has the form AxA xAx for a unique x∈Rnx \in \mathbb{R}^nx∈Rn. We seek x^\hat{x}x^ so that

p=Ax^p = A \hat{x}p=Ax^

is the orthogonal projection of bbb onto C(A)C(A)C(A). Again the error e=b−Ax^e = b - A\hat{x}e=b−Ax^ must be orthogonal to every vector in the subspace — in particular, orthogonal to every column of AAA:

A⊤(b−Ax^)=0.A^\top (b - A\hat{x}) = 0.A⊤(b−Ax^)=0.

Rearrange:

A⊤A x^=A⊤b.A^\top A\, \hat{x} = A^\top b.A⊤Ax^=A⊤b.

These are the normal equations. Because AAA has full column rank, A⊤AA^\top AA⊤A is invertible (it is n×nn \times nn×n, symmetric, and positive definite: x⊤A⊤Ax=∥Ax∥2=0x^\top A^\top A x = \|Ax\|^2 = 0x⊤A⊤Ax=∥Ax∥2=0 forces Ax=0Ax = 0Ax=0 and hence x=0x = 0x=0). Solve:

x^=(A⊤A)−1A⊤b,p=Ax^=A(A⊤A)−1A⊤b.\hat{x} = (A^\top A)^{-1} A^\top b, \qquad p = A\hat{x} = A(A^\top A)^{-1} A^\top b.x^=(A⊤A)−1A⊤b,p=Ax^=A(A⊤A)−1A⊤b.

Reduction to the line formula. When AAA is a single column aaa, the matrix A⊤AA^\top AA⊤A is the scalar a⊤aa^\top aa⊤a, and (A⊤A)−1A⊤b(A^\top A)^{-1} A^\top b(A⊤A)−1A⊤b becomes (a⊤b)/(a⊤a)(a^\top b)/(a^\top a)(a⊤b)/(a⊤a) — exactly the line formula from the previous section.

Worked example. Let

A=(101101),b=(231).A = \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix}, \qquad b = \begin{pmatrix} 2 \\ 3 \\ 1 \end{pmatrix}.A=​110​011​​,b=​231​​.

The two columns of AAA are independent, so they span a plane in R3\mathbb{R}^3R3. Compute

A⊤A=(2112),(A⊤A)−1=13(2−1−12),A⊤b=(54).A^\top A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}, \qquad (A^\top A)^{-1} = \frac{1}{3}\begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}, \qquad A^\top b = \begin{pmatrix} 5 \\ 4 \end{pmatrix}.A⊤A=(21​12​),(A⊤A)−1=31​(2−1​−12​),A⊤b=(54​).

Then

x^=13(2−1−12)(54)=(21),p=Ax^=(231).\hat{x} = \frac{1}{3}\begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}\begin{pmatrix} 5 \\ 4 \end{pmatrix} = \begin{pmatrix} 2 \\ 1 \end{pmatrix}, \qquad p = A\hat{x} = \begin{pmatrix} 2 \\ 3 \\ 1 \end{pmatrix}.x^=31​(2−1​−12​)(54​)=(21​),p=Ax^=​231​​.

In this case p=bp = bp=b: the target already lies in C(A)C(A)C(A). The residual is zero, and the normal equations hold trivially.

If bbb is not in C(A)C(A)C(A). The same formulas still produce the closest point p∈C(A)p \in C(A)p∈C(A). The residual e=b−pe = b - pe=b−p lands in N(A⊤)N(A^\top)N(A⊤) — the left null space from Week 6 — so A⊤e=0A^\top e = 0A⊤e=0 by construction. Week 8 will use exactly this setup for least squares: solve Ax^≈bA\hat{x} \approx bAx^≈b by minimizing ∥b−Ax∥\|b - Ax\|∥b−Ax∥.


The Projection Matrix#

The subspace formula p=A(A⊤A)−1A⊤bp = A(A^\top A)^{-1} A^\top bp=A(A⊤A)−1A⊤b is linear in bbb. The matrix that implements it is the projection matrix

P=A(A⊤A)−1A⊤.P = A(A^\top A)^{-1} A^\top.P=A(A⊤A)−1A⊤.

Then p=Pbp = P bp=Pb for every bbb. Once PPP is built from AAA, projecting any number of vectors is a single matrix–vector multiply.

Two algebraic properties characterize orthogonal projections:

  1. Idempotence: P2=PP^2 = PP2=P.
    Projecting twice does nothing new: the first application lands in C(A)C(A)C(A), and vectors already in C(A)C(A)C(A) are fixed by PPP. Explicitly,

    P2=A(A⊤A)−1A⊤⋅A(A⊤A)−1A⊤=A(A⊤A)−1A⊤=P,P^2 = A(A^\top A)^{-1} A^\top \cdot A(A^\top A)^{-1} A^\top = A(A^\top A)^{-1} A^\top = P,P2=A(A⊤A)−1A⊤⋅A(A⊤A)−1A⊤=A(A⊤A)−1A⊤=P,

    because A⊤A(A⊤A)−1=IA^\top A (A^\top A)^{-1} = IA⊤A(A⊤A)−1=I cancels in the middle.

  2. Symmetry: P⊤=PP^\top = PP⊤=P.
    Orthogonal projection is a symmetric linear map. Taking the transpose of the formula,

    P⊤=(A(A⊤A)−1A⊤)⊤=A((A⊤A)−1)⊤A⊤=A(A⊤A)−1A⊤=P,P^\top = \bigl(A(A^\top A)^{-1} A^\top\bigr)^\top = A\bigl((A^\top A)^{-1}\bigr)^\top A^\top = A(A^\top A)^{-1} A^\top = P,P⊤=(A(A⊤A)−1A⊤)⊤=A((A⊤A)−1)⊤A⊤=A(A⊤A)−1A⊤=P,

    using that A⊤AA^\top AA⊤A (and its inverse) is symmetric.

Conversely, any matrix that is both symmetric and idempotent is the orthogonal projection onto its column space.

Geometry of the properties.

  • P2=PP^2 = PP2=P says the map is a projection (not necessarily orthogonal): applying it again cannot move the result.
  • P⊤=PP^\top = PP⊤=P forces the projection to be orthogonal — the residual b−Pbb - Pbb−Pb is orthogonal to the subspace. Without symmetry you can have oblique projections that still satisfy P2=PP^2 = PP2=P but do not minimize distance.

Eigenvalues. Because P2=PP^2 = PP2=P, every eigenvalue λ\lambdaλ satisfies λ2=λ\lambda^2 = \lambdaλ2=λ, so λ∈{0,1}\lambda \in \{0, 1\}λ∈{0,1}. The eigenspace for λ=1\lambda = 1λ=1 is C(P)=C(A)C(P) = C(A)C(P)=C(A) (the subspace we project onto); the eigenspace for λ=0\lambda = 0λ=0 is the orthogonal complement N(P)=N(A⊤)N(P) = N(A^\top)N(P)=N(A⊤). Trace equals rank: tr⁡(P)=rank⁡(P)=n\operatorname{tr}(P) = \operatorname{rank}(P) = ntr(P)=rank(P)=n when AAA is m×nm \times nm×n with full column rank.

Line case again. For a single nonzero column aaa,

P=aa⊤a⊤a,P = \frac{a a^\top}{a^\top a},P=a⊤aaa⊤​,

the familiar outer-product formula. Check: Pa=aP a = aPa=a and Pv=0P v = 0Pv=0 whenever v⊥av \perp av⊥a.


Knowledge check#

Question 1 of 3

The projection matrix P = A(A^T A)^{-1}A^T satisfies:

P² = P
P² = I
P is diagonal
P^T = -P

Browser lab#

Build a projection matrix onto a 2D subspace of R3\mathbb{R}^3R3 and verify P2=PP^2 = PP2=P (idempotence) and P⊤=PP^\top = PP⊤=P (symmetry). The columns of AAA span the subspace; p=Pbp = P bp=Pb is the orthogonal projection of bbb onto that plane.

python · runs in browser
import numpy as np

A = np.array([[1., 0.],
              [1., 1.],
              [0., 1.]])
b = np.array([2., 3., 1.])

P = A @ np.linalg.inv(A.T @ A) @ A.T
p = P @ b

print("Projection matrix P =\n", P)
print("Projected vector p =", p)
print("P @ P ≈ P:", np.allclose(P @ P, P))
print("P.T ≈ P:", np.allclose(P.T, P))
print("residual A.T @ (b - p) ≈ 0:", np.allclose(A.T @ (b - p), 0))
← Previous
Week 6: The Four Fundamental Subspaces
Next →
Week 8: Least Squares and QR
On this page
  • Orthogonal Vectors and Subspaces
  • Projection onto a Line
  • Projection onto a Subspace
  • The Projection Matrix
  • Knowledge check
  • Browser lab