Linear Algebra, Live
Strang §4.2 · Projection matrices

The projection matrix P

Slide 2 projected one b at a time, with two dot products each time. Now we build one matrix P that projects every b at once: p = Pb. Think of the sun again. Its direction is fixed, and every stick in the field gets its shadow by the same rule. P is that rule written as a matrix. For the line through a it is P = aaᵀ / aᵀa. Using P twice changes nothing, because the shadow of a shadow is the same shadow: P² = P. The same idea works for a plane or any column space, and it leads to the most important equation of this lesson, AᵀAx̂ = Aᵀb.

Lesson 5 · slide 3Projection matrix
P = aaᵀ / aᵀa    P = A(AᵀA)⁻¹Aᵀ    P² = P
Key ideas
  1. P multiplies any vector b and returns its projection p = Pb.
  2. For a line, P = aaᵀ / aᵀa: a column times a row, divided by a number.
  3. P² = P: projecting a second time changes nothing. P is also symmetric, Pᵀ = P, because (aaᵀ)ᵀ = aaᵀ.
  4. For the column space of A (independent columns), P = A(AᵀA)⁻¹Aᵀ.
  5. (I − P)b = e. In the plane, I − P projects onto the perpendicular line; in 3D, I − P for a line projects onto the perpendicular plane, and vice versa.

One matrix for every b

Often we project many vectors, like every reading from a sensor. So we build one matrix that works for any b.

Start from p = a(aᵀb) / aᵀa. Products can be regrouped: a(aᵀb) = (aaᵀ)b. So p = (aaᵀ / aᵀa) b, and the matrix in brackets is P.

Watch the order. aᵀa is a row times a column: one number (here 5). aaᵀ is a column times a row: a whole matrix (here 2 by 2).

a = 12:   aaᵀ = 1224,   aᵀa = 5
P = 0.20.40.40.8
Pb for b = 43: 0.8 + 1.21.6 + 2.4 = 24
slide 2 way: aᵀb = 4 + 6 = 10,   x̂ = 10 / 5 = 2,   p = 2·12 = 24 ✓
Building P for a = 12: a column times a row, then divide by one number. Multiplying P by itself gives the same matrix.

The same P works for any other b. Take b = −13: Pb = −0.2 + 1.2−0.4 + 2.4 = 12. Check: aᵀb = −1 + 6 = 5, x̂ = 1, p = 12 ✓.

Pb = 24 is the shadow of b = 43 on the line through 12. The leftover e = 2−1 meets the line at a right angle.

Projecting twice changes nothing

Once p is on the line, projecting it again gives p. So P(Pb) = Pb, which says P² = P. Check with p = 24: P24 = 0.4 + 1.60.8 + 3.2 = 24 ✓.

In the lab (the code and picture below), show(P) draws each grid point b and its projection Pb: every shadow lies on the line through 12. Many points share one shadow, so P has no inverse. You can't get b back from its shadow. The ad − bc test from lesson 3 agrees: 0.2·0.8 − 0.4·0.4 = 0.16 − 0.16 = 0.

The leftover part has its own matrix: (I − P)b = b − Pb = e. For our a:

I − P = 0.8−0.4−0.40.2,   (I − P)(4, 3) = 3.2 − 1.2−1.6 + 0.6 = 2−1 = e ✓

Projecting onto a column space

Now project b onto the column space of a matrix A with independent columns. That is a plane, or a bigger flat piece of space. Then p = Ax̂, where x̂ holds one number per column (x̂ is now a vector, not a single number). The error e = b − Ax̂ must be perpendicular to every column of A. The rows of Aᵀ are those columns, so this says Aᵀe = 0.

Aᵀ(b − Ax̂) = 0
AᵀA x̂ = Aᵀb
x̂ = (AᵀA)⁻¹Aᵀb,    p = A(AᵀA)⁻¹Aᵀ b

So P = A(AᵀA)⁻¹Aᵀ. Don't split the inverse: A is not square, so A⁻¹ does not exist. (The next slide shows why AᵀA has an inverse.) With one column a, this is aaᵀ/aᵀa again. The middle equation, AᵀAx̂ = Aᵀb, is the most important one in this lesson. The simplest case is the floor of a room:

A = 100100: the columns 100 and 010 span the floor
AᵀA = I,   b = 345:   x̂ = Aᵀb = 34,   p = Ax̂ = 340,   e = 005

The shadow of a point on the floor keeps its two floor numbers and drops the height. A slanted plane works the same way:

The sheet is the column space of A with columns 110 and 011. b = 300 sits off it. Its shadow p = 2·110 − 1·011 = 21−1 sits on it.

Keep reading with the full course

Finish lesson 5 and you will be able to: fit the best line to noisy sensor data.

Still locked here:

  • The rest of this explanation
  • 4 more examples with step-by-step solutions
  • Five extra members-only problems with worked solutions

$20 once, lifetime access. Lessons 1 to 3 stay free.

Examples

Example 1 · Onto the x-axis

a = 10: aaᵀ = 1000, aᵀa = 1.

Show solutionHide solution
P = 1000,   P57 = 50

The projection keeps the x component and drops the y component: a shadow cast straight down onto the x-axis.

Exercise Build the projection matrix P onto the line through a = (1, 2). Edit the code and press Run.
slide_3.py Loading Python…
1
Output · Ctrl+Enter runs
Press Run to execute this slide's code. Ctrl+Enter works too.

Questions and comments

Stuck on something, or found a mistake? Ask here and I'll answer. You sign in with GitHub.

The full course

From Ax = b to PCA, by running it

Lessons 1 to 3 are free. Finish all eight and you will be able to:

You get: all 8 lessons with Python labs · every worked example and solution · 5 extra problems per lesson · your progress tracked · answers to your questions · every future update.

$20 once · lifetime access
Continue to checkout →

Already a member? Log in to the course