The projection matrix P is put to work. First a recap of what the magic formula does, tested on the two extreme cases, then the full least-squares problem worked end to end: fitting the best straight line through three points that no line passes through. The normal equations solve it, the error vector comes out perpendicular to the column space, and a proof shows why A transpose A is invertible whenever A has independent columns.
What the projection matrix does: two extreme cases
Last lecture ended with a magic formula — the projection matrix
P=A(ATA)−1AT.
What is it doing? Multiply by any b: Pb is supposed to project b to the nearest point in the column space of A. Strang recaps by testing the two extreme cases.
Case 1: b is in the column space already. Then projecting should change nothing — Pb=b. Why does the formula deliver that? A vector in the column space is a combination of the columns, and Strang insists you know how to write one: it has the form Ax. (“I’m going to stick that on the quiz or the final for sure.”) Feed b=Ax into the formula:
Pb=A(ATA)−1ATAx=AI(ATA)−1(ATA)x=Ax=b.
Cancel, cancel — the ATA meets its inverse, leaving Ax, which was b.
Case 2: b is perpendicular to the column space. Picture the column space as a plane and b sticking straight up at ninety degrees. The nearest point in the plane is the origin: Pb should be 0. Which vectors are perpendicular to the column space? The four fundamental subspaces answer instantly: they are the vectors in the null space of AT. So ATb=0, and the formula dies right at its last factor:
Pb=A(ATA)−10ATb=0.
The average vector is neither extreme: it has a piece p in the column space and a piece e perpendicular to it. The projection preserves the first piece and kills the second, and the two pieces add back to the original: p+e=b.
The best straight line through three points
Now put the formula to work on the problem started at the end of last lecture. Three data points: at times t=1,2,3 the measured heights are b=1,2,2. The first two points suggest a nice forty-five-degree line — but the third point doesn’t lie on it. No line goes through all three. We want the best line y=C+Dt.
If a line did go through all three points, C and D would solve three equations:
Three equations, two unknowns, no solution: the two columns of A are independent — they’re a basis for the column space — but that column space doesn’t contain b.
Strang keeps two pictures on the board, and insists you see both. Picture one is in the t–y plane: three points, a candidate line, and three vertical errors e1,e2,e3 — the gap at each t between the data value bi and the line’s value pi. Picture two is a vector picture in R3: the vector b=(1,2,2), the column space of A spanned by (1,1,1) and (1,2,3), and the nearest point p=(p1,p2,p3) in that column space. Same problem twice: if we replaced the data 1,2,2 by the numbers p1,p2,p3, the three equations would be solvable — a line goes through the p‘s — because the vector p is in the column space. It’s the closest such vector.
An aside Strang takes seriously: fitting straight lines is a big part of statistics — the right word is regression, linear regression, and this sum of squares is its measure of error. Statisticians like it because it leads to a beautiful linear system, but they’re careful about the squaring. Suppose a fourth measurement at t=0 was way off. Its squared error would be way out of sight compared to the others, and the whole problem turns topsy-turvy over one point — an outlier, which could be a mistake after all. Least squares is the most used method, but not exclusively used, because it overcompensates for outliers.
And what do we expect of ATA before continuing? Symmetric — check. Invertible — check. (Near the end of the course Strang will add: positive definite, a future fact about this crucial matrix.) The normal equations, written out:
3C+6D6C+14D=5=11
Before solving, Strang derives the same equations a second way — from calculus. The total squared error is a function of two variables,
E(C,D)=(C+D−1)2+(C+2D−2)2+(C+3D−2)2,
and at the minimum both partial derivatives vanish. Because we’re differentiating squares, the derivatives are linear — that’s the beauty of these squares — and ∂E/∂C=0 gives the first normal equation, ∂E/∂D=0 the second. Wherever you look, these equations keep coming.
Now solve by elimination, “because that’s the only thing I know how to do”: subtract twice the first equation from the second to get 2D=1, so D=21; back substitution gives 3C+3=5, so C=32. The best line is
y=32+21t.
The projection p and the error e
With the line in hand, read off the points on the line — the components of p:
What do we know about this error vector? First, p+e=b — the two pieces rebuild the original. Second, p and e are perpendicular. Dare to verify: the dot product is −367+3620−3613=0. (“Thank you, God.”)
But we know even a little more: e is perpendicular not just to this particular p — it’s perpendicular to the whole column space. Test it against a nice vector in the column space, (1,1,1): the dot product is −61+62−61=0. And against (1,2,3): −61+64−63=0 again.
Why A transpose A is invertible
The whole calculation leaned on ATA being invertible — Strang announced it as the chapter started, and now he pays the debt with a proof. He doesn’t hammer away at many proofs in this course, “but this is like the central fact and it brings in all the stuff we know.”
(If A has independent columns and Ax=0, then x=0 — Strang flags that implication too as “a fill-in question on the final exam.”)
Looking ahead: orthonormal columns
One case makes the geometry even better. Columns are certainly independent if they’re perpendicular — ruling out the zero column by giving them all length one. Perpendicular unit vectors, like (1,0,0), (0,1,0), (0,0,1), are called orthonormal: ortho for perpendicular, normal for unit length. Those are the best columns you could ask for — for the matrix with those three columns, ATA is the identity.
A final example, Strang’s absolute favorite pair of orthonormal vectors in the plane:
[cosθsinθ],[−sinθcosθ]
Both unit vectors, and the angle between them is ninety degrees. The job next time: see why orthonormal vectors are great, and then make vectors orthonormal by picking the right basis.
Problems
Work these before revealing the solutions — the lecture’s worked example is the template for all of them.
Problem 16.1Best line through three points
Find the best straight line y=C+Dt through the points (1,0), (2,1), (3,3) in the least squares sense. Set up A, b, and the normal equations, then solve for C^ and D^.
Show solution
The three (unsolvable) equations are C+D=0, C+2D=1, C+3D=3, so
A=111123,b=013.
Then ATA=[36614] (same matrix as the lecture — same t‘s) and ATb=[0+1+30+2+9]=[411].
Normal equations: 3C+6D=4 and 6C+14D=11. Subtract twice the first from the second: 2D=3, so D=23. Back substitute: 3C+9=4, so C=−35. Best line: y=−35+23t.
Problem 16.2Check p + e = b and orthogonality
For the line found in Problem 16.1, compute the projection p=Ax^ and the error e=b−p. Verify that e is perpendicular to both columns of A.
Show solution
Evaluate the line at t=1,2,3: −35+23=−61, then −35+3=34, then −35+29=617. So
p=−1/64/317/6,e=b−p=1/6−1/31/6.
Against (1,1,1): 61−62+61=0. Against (1,2,3): 61−64+63=0. Both zero, so e is perpendicular to the whole column space — the same (61,−62,61) pattern of errors as the lecture, with signs flipped.
Problem 16.3Extreme cases of P
Let A=111123 as in the lecture. Without computing P entry by entry, find Pb for (a) b=234 and (b) b=1−21. Justify each answer using the two extreme cases.
Show solution
(a) b=(2,3,4) is in the column space: it equals 1⋅(1,1,1)+1⋅(1,2,3), i.e. b=Ax with x=(1,1). Vectors already in the column space are unchanged by projection, so Pb=b=(2,3,4).
(b) Check b=(1,−2,1) against the columns: (1,−2,1)⋅(1,1,1)=0 and (1,−2,1)⋅(1,2,3)=1−4+3=0. So ATb=0: this b is in the null space of AT, perpendicular to the column space, and the formula kills it at its last factor. Pb=0.
Problem 16.4I minus P is a projection
Suppose P is a projection matrix, so PT=P and P2=P. Show algebraically that Q=I−P satisfies the same two properties, and identify the subspace that Q projects onto when P projects onto the column space of A.
Show solution
Symmetric:QT=(I−P)T=IT−PT=I−P=Q.
Idempotent:Q2=(I−P)(I−P)=I−P−P+P2=I−2P+P=I−P=Q, using P2=P.
Qb=b−Pb=e, the error part of b. Since e is perpendicular to the column space, Q projects onto the orthogonal complement of C(A) — the null space of AT.
Problem 16.5When A transpose A fails
Let A=111222, whose columns are dependent. Compute ATA and show directly that it is singular, by finding a nonzero vector in its null space. Explain how this fits the theorem proved in lecture.
Show solution
ATA=[121212]111222=[36612].
The second row is twice the first, so ATA is singular. Take x=[2−1]: then ATAx=[6−612−12]=0.
This is exactly the lecture’s theorem run in reverse: the proof showed ATAx=0 forces Ax=0, and indeed Ax=2c1−c2=0 here because column two is twice column one. Dependent columns give A a nonzero null space, and ATA inherits it — the theorem’s hypothesis of independent columns is necessary, not just convenient.