投影的几何核心是误差向量垂直于目标子空间;沿这个条件推出 x̂ = (AᵀA)⁻¹Aᵀb 与投影矩阵 P = A(AᵀA)⁻¹Aᵀ,并用一条直线拟合收尾。
Projections onto Subspaces
The geometry of projection is one condition: the error is perpendicular to the target subspace. From it follow x̂ = (AᵀA)⁻¹Aᵀb and P = A(AᵀA)⁻¹Aᵀ, applied to fitting a line.
This chapter handles the case where Ax=b has no solution. No solution does not mean no answer: b is outside the column space, but the column space has a nearest point. Replacing b by that point makes the system solvable.
That is projection. Geometrically it is a foot of a perpendicular; algebraically it is least squares.
Timeline
Time
Topic
0:10
The projection formula
2:03
The one-dimensional projection matrix
5:45
Linearity of projection
10:52
Column space and rank of the projection matrix
16:17
Orthogonality is the key
20:12
The columns must be independent
22:01
When b lies outside the column space
25:30
Two equations from the perpendicular error
28:48
Explaining projection with the four subspaces
33:18
Where the normal equation comes from
36:00
The projection matrix P
37:31
When A is invertible, P=I
39:18
You cannot split ATA apart
44:09
Fitting a line to three points
46:56
Building A and b
48:49
The computation left for next time
The one-dimensional case: projecting onto a line
Figure:Projection geometry, the projection matrix, and a three-point least-squares fit。
Let the line be spanned by a, and project b onto it.
The projection lies on the line, so it has the form p=xa. The key condition is that the error e=b−xa is perpendicular to the line:
a⊤(b−xa)=0.
Expanding,
a⊤b=xa⊤a⟹x=a⊤aa⊤b.
Therefore
p=xa=a⊤aa⊤ba.
Three formulas to remember
Object
Formula
Coefficient
x=a⊤aa⊤b
Projection vector
p=ax
Projection matrix
P=a⊤aaa⊤
P is n×n: the numerator is a column times a row (a matrix), the denominator is a scalar.
Two sanity checks
Doubling b doubles the projection.
Doubling a leaves the projection unchanged: the line is the same, and numerator and denominator both gain a factor of 4.
Two properties of a projection matrix
P⊤=P,P2=P.
The first follows from (aa⊤)⊤=aa⊤. The second is geometric: projecting twice is the same as projecting once. Algebraically,
P2=(a⊤a)2aa⊤aa⊤=(a⊤a)2a(a⊤a)a⊤=a⊤aaa⊤=P.
Conversely, a symmetric idempotent matrix is a projection matrix.
Projecting onto a subspace
Let the subspace be the column space of A, whose columns form a basis and are therefore independent.
The projection is p=Ax^, with x^ the coefficients to be found. The condition is still
e=b−Ax^⊥C(A).
Being perpendicular to the whole column space means being perpendicular to each column:
A⊤(b−Ax^)=0.
Rearranging gives the normal equations:
A⊤Ax^=A⊤b.
The solution is
x^=(A⊤A)−1A⊤b,
and the projection vector and matrix are
p=Ax^=A(A⊤A)−1A⊤b,P=A(A⊤A)−1A⊤.
Correspondence with the one-dimensional formula
In one dimension A is the single column a, and (A⊤A)−1 is division by a⊤a:
P=a⊤aaa⊤.
In higher dimensions division is replaced by inversion — the difference between a scalar and a matrix.
Where the error lives
From A⊤e=0,
e∈N(A⊤)=C(A)⊥.
This is exactly the orthogonality from the previous lecture: the error lies in the left null space, perpendicular to the column space. Geometry and the four subspaces meet precisely here.
Something you must not do
It is tempting to split the inverse:
(A⊤A)−1=A−1(A⊤)−1.
That is wrong, because A is not square and has no inverse. This is the typical case of the chapter: more rows than columns. The split is legal only when A is square and invertible, and then the column space is all of Rn and the projection matrix is the identity I.
Least squares: fitting a line to three points
Given the points (1,1),(2,2),(3,2), find the line
b=C+Dt
with the smallest total error.
If the line passed through all three points, it would satisfy
C+DC+2DC+3D=1,=2,=2.
In matrix form:
A111123x[CD]=b122.
Three equations, two unknowns, generally unsolvable. Instead of solving it, solve the normal equations:
A⊤Ax^=A⊤b.
The next lecture finishes the arithmetic, giving C=2/3 and D=1/2, so the best line is
b=32+21t.
Why use every point
The alternative is to discard an equation and solve a square system. That amounts to declaring some measurements perfect and others worthless, with no justification. Least squares lets every point contribute, weighted by squared error.
The price is sensitivity to outliers: a point far from the line has its error squared, so it can drag the whole fit. Statistics therefore also offers robust regression.
Takeaways
The only geometric condition for a projection is that the error is perpendicular to the target subspace.
One dimension: x=a⊤b/a⊤a and P=aa⊤/a⊤a.
Higher dimensions: A⊤Ax^=A⊤b and P=A(A⊤A)−1A⊤.
Projection matrices are symmetric and idempotent: P⊤=P and P2=P.
The error lies in the left null space, orthogonal to the column space.
Least squares is projection applied to an unsolvable system.
Check your understanding
1. Why does "the error is perpendicular to the line" determine the projection uniquely?
Reference answer: Every point on the line is p=xa, and the condition
a⊤(b−xa)=0
expands to x=a⊤aa⊤b. Since a=0, the denominator a⊤a>0, so x is determined uniquely.
Geometrically: if two distinct points p=q on the line both had perpendicular error, then p−q lies on the line while
p−q=(b−q)−(b−p)
is a difference of two vectors perpendicular to the line, hence also perpendicular to it. A vector that is both on the line and perpendicular to it satisfies (p−q)⊤(p−q)=0, so p=q, a contradiction. The foot is unique.
2. If a is replaced by 3a, does the projection matrix change? Why?
Reference answer: It does not change. Substituting,
P′=(3a)⊤(3a)(3a)(3a)⊤=9a⊤a9aa⊤=a⊤aaa⊤=P.
The reason: projection depends on the subspace (the line), not on which vector spans it, and a and 3a span the same line. Likewise, replacing b by 2b doubles the projection — projection is linear in b.
3. Prove that the higher-dimensional projection matrix satisfies P2=P.
Reference answer: With P=A(A⊤A)−1A⊤,
P2=A(A⊤A)−1A⊤A(A⊤A)−1A⊤.
The middle three factors satisfy A⊤A(A⊤A)−1=I, so
P2=A(A⊤A)−1A⊤=P.
Geometrically: once a vector has been projected into the column space, it already lies there, so projecting again leaves it fixed. Also P⊤=P, because
P⊤=(A(A⊤A)−1A⊤)⊤=A((A⊤A)−1)⊤A⊤=A(A⊤A)−1A⊤=P,
using that A⊤A is symmetric and so is its inverse. Symmetry plus idempotence characterizes projection matrices.
4. Why can (A⊤A)−1 not be split into A−1(A⊤)−1?
Reference answer: Because in this chapter A is m×n with m>n and is not square, so it has no inverse at all. The identity B−1C−1=(CB)−1 applies only to invertible square matrices; writing A−1 for a non-square matrix is meaningless.
A⊤A is n×n and is invertible when the columns of A are independent, so (A⊤A)−1 exists — but that is a different statement from "A is invertible." Only when A is itself an invertible n×n matrix does (A⊤A)−1=A−1(A⊤)−1 hold, and then the column space is all of Rn and the projection collapses to
P=A(A⊤A)−1A⊤=AA−1(A⊤)−1A⊤=I.
5. Write the A, x, and b for fitting a line b=C+Dt through three points.
Reference answer: The points are (t,b)=(1,1),(2,2),(3,2), and b=C+Dt gives one equation per point:
C+D⋅1C+D⋅2C+D⋅3=1,=2,=2.
Collecting coefficients of the unknowns (C,D):
A=111123,x=[CD],b=122.
The first column is the constant column (the intercept C), the second holds the t values (the slope D). Three equations, two unknowns: usually unsolvable, so solve the normal equations A⊤Ax^=A⊤b for the least-squares solution.
How this connects to the course
The previous lecture proved the orthogonality of the four subspaces; this one uses it to construct projections. The next carries the projection matrix through a numerical least-squares example and proves that A⊤A is invertible when the columns of A are independent.