Orthogonal Vectors and Subspaces#
Week 1 defined the dot product of two vectors as
Two vectors are orthogonal when their dot product is zero:
Geometrically, orthogonal vectors meet at a right angle. Algebraically, the test is a single number. The zero vector is orthogonal to every vector, because always.
Orthogonal subspaces. Two subspaces are orthogonal when every vector in one is orthogonal to every vector in the other:
It is enough to check bases: if every basis vector of is orthogonal to every basis vector of , 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 matrix . Orthogonality locks them into complementary pairs:
- In : the row space and the null space are orthogonal complements. Every row of is orthogonal to every with (because means each row dotted with is zero). Dimensions add: , so together they fill all of .
- In : the column space and the left null space are orthogonal complements. If , then is orthogonal to every column of . Dimensions add: .
We write and . That is the structural fact Week 6 previewed: the kernel of 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 decomposes uniquely as
with . The piece is the orthogonal projection of onto the column space — the closest point of to . The rest of this week builds the formulas that produce .
Projection onto a Line#
Start with the simplest subspace: a line through the origin spanned by a nonzero vector . Given a vector , we want the point on that line closest to . Write
for some scalar . The error (residual) is . For to be the orthogonal projection, the error must be orthogonal to the line — that is, orthogonal to :
Expand and solve for :
Therefore the projection is
Geometric reading. The scalar is the coordinate of along the unit direction of , scaled by . The formula never needs an explicit unit vector: the factor absorbs the length of .
Worked example. Project onto the line spanned by .
So
The error is , and — orthogonal, as required. Notice is the squared distance from to the line; any other point on the line would be farther.
Special cases.
- If already lies on the line, then for some , and , so .
- If , then and — the nearest point on the line is the origin.
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 by a higher-dimensional subspace. Let the columns of an matrix form a basis for the subspace we project onto (so has full column rank , and the subspace is ). Any point in the subspace has the form for a unique . We seek so that
is the orthogonal projection of onto . Again the error must be orthogonal to every vector in the subspace — in particular, orthogonal to every column of :
Rearrange:
These are the normal equations. Because has full column rank, is invertible (it is , symmetric, and positive definite: forces and hence ). Solve:
Reduction to the line formula. When is a single column , the matrix is the scalar , and becomes — exactly the line formula from the previous section.
Worked example. Let
The two columns of are independent, so they span a plane in . Compute
Then
In this case : the target already lies in . The residual is zero, and the normal equations hold trivially.
If is not in . The same formulas still produce the closest point . The residual lands in — the left null space from Week 6 — so by construction. Week 8 will use exactly this setup for least squares: solve by minimizing .
The Projection Matrix#
The subspace formula is linear in . The matrix that implements it is the projection matrix
Then for every . Once is built from , projecting any number of vectors is a single matrix–vector multiply.
Two algebraic properties characterize orthogonal projections:
-
Idempotence: .
Projecting twice does nothing new: the first application lands in , and vectors already in are fixed by . Explicitly,because cancels in the middle.
-
Symmetry: .
Orthogonal projection is a symmetric linear map. Taking the transpose of the formula,using that (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.
- says the map is a projection (not necessarily orthogonal): applying it again cannot move the result.
- forces the projection to be orthogonal — the residual is orthogonal to the subspace. Without symmetry you can have oblique projections that still satisfy but do not minimize distance.
Eigenvalues. Because , every eigenvalue satisfies , so . The eigenspace for is (the subspace we project onto); the eigenspace for is the orthogonal complement . Trace equals rank: when is with full column rank.
Line case again. For a single nonzero column ,
the familiar outer-product formula. Check: and whenever .
Knowledge check#
The projection matrix P = A(A^T A)^{-1}A^T satisfies:
Browser lab#
Build a projection matrix onto a 2D subspace of and verify (idempotence) and (symmetry). The columns of span the subspace; is the orthogonal projection of onto that plane.
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))