Linear Algebra, Live
Strang §7.4 · The pseudoinverse

The pseudoinverse and the condition number

Slide 5 used the SVD to read data. Now we use it to undo a matrix. Lesson 3 said a singular or rectangular matrix has no inverse, and that is true: some information is lost for good. Think of the shadow of a stick on a wall. From the shadow you can tell how long the stick is from side to side, but not how far it points toward you. That part is gone. The pseudoinverse A⁺ does the best possible undo: it reverses every stretch that can be reversed, and sets the lost directions to zero. The same SVD also gives the condition number σ₁/σₙ (σₙ is the smallest singular value), which warns when a problem is so close to losing a direction that small errors blow up.

Lesson 8 · slide 6Pseudoinverse
A⁺ = VΣ⁺Uᵀ (Σ⁺: 1/σ for each nonzero σ)    x⁺ = A⁺b    condition number = σ₁ / σₙ
Key ideas
  1. Σ⁺ has the transposed shape of Σ (n by m when A is m by n). Its diagonal holds 1/σ for each nonzero σ; everything else is zero.
  2. A⁺ = VΣ⁺Uᵀ = (1/σ₁)v₁u₁ᵀ + … + (1/σᵣ)vᵣuᵣᵀ, using the nonzero σ's only. If A is invertible, A⁺ = A⁻¹.
  3. x⁺ = A⁺b is a least squares solution (lesson 5). When many x are equally good, A⁺ picks the shortest.
  4. The condition number σ₁/σₙ (σₙ is the smallest singular value) says how much errors in b can be amplified in x. It is infinite when σₙ = 0.

The best possible undo

A = UΣVᵀ is turn, stretch, turn. To undo it, go backwards: turn back with Uᵀ, undo each stretch by dividing by σ, turn back with V. Turns can always be undone (Uᵀ undoes U because UᵀU = I). A stretch by σ can be undone by 1/σ, unless σ = 0. A direction squashed to zero can't be brought back, so A⁺ leaves it at zero.

A = UΣVᵀ,   so undo in reverse order:   A⁺ = VΣ⁺Uᵀ
Σ = σ₁000  →  Σ⁺ = 1/σ₁000

Written as pieces, like slide 3, the undo is a sum over the nonzero σ's only:

A⁺ = (1/σ₁)v₁u₁ᵀ + (1/σ₂)v₂u₂ᵀ + … + (1/σᵣ)vᵣuᵣᵀ
Σ⁺ has the transposed shape of Σ: for a 3 by 2 A, Σ is 3 by 2 and Σ⁺ is 2 by 3, with 1/σ₁, 1/σ₂ on its diagonal and zeros elsewhere

If A is invertible (square, no zero σ), then Σ⁺ = Σ⁻¹ and A⁺ = A⁻¹. A small example: A = 3000 has σ₁ = 3, σ₂ = 0, so A⁺ = 1/3000: the x-stretch is undone, the squashed y-direction stays at zero.

A worked example: two equations that disagree

This A squashes the whole circle onto one line. v₁ is stretched by σ₁ = 2; v₂ shrinks to nothing (σ₂ = 0). That lost direction can't be undone.
A = 1111, b = 24:   x + y = 2 and x + y = 4 contradict each other
σ₁ = 2 with u₁ = v₁ = 11/√2,   σ₂ = 0
A⁺ = v₁(1/2)u₁ᵀ = ½ · ½1111 = ¼1111
x⁺ = A⁺b = ¼2 + 42 + 4 = ¼66 = 1.51.5
The two equations are parallel lines. They never cross, so no x solves both.

The best compromise is x + y = 3 (the average of 2 and 4: it makes the two errors equal and as small as possible, which is what least squares from lesson 5 gives). But x + y = 3 is still a whole line of answers, like 30 or 12. Which one does A⁺ pick? The shortest one. Take any answer, such as 30, and project it onto the line through v₁ (lesson 5). The part you remove points along v₂, the direction A can't see, so Ax doesn't change:

The answer 30 drops onto the line through 11 at p = 1.51.5. The removed part 1.5−1.5 is in the nullspace, so p is still a best answer, and the shortest one.

Why the shortest? Every best answer is p plus some multiple of v₂, and p ⟂ v₂, so by Pythagoras its squared length is ‖p‖² plus something positive. Only p itself has nothing added.

Check: A1.51.5 = 33.   Length of 1.51.5 = √4.5 ≈ 2.12, shorter than ‖30‖ = 3 or ‖12‖ = √5 ≈ 2.24

The condition number

If σₙ is tiny compared with σ₁, A almost squashes a direction. Solving Ax = b divides by that tiny σₙ, so small errors in b blow up. The ratio σ₁/σₙ is the condition number. If σₙ = 0, like the A = 1111 above with σ₂ = 0, the condition number is infinite: that direction is lost completely. We compare errors by their relative size: the length of the error divided by the length of the vector. Start with a clear case:

A = 2000.2:   σ₁ = 2, σ₂ = 0.2, condition number 2/0.2 = 10
b = 20 gives x = 10.   A small error: b = 20.02 gives x = 10.1
b moved by 0.02 out of 2 (1%); x moved by 0.1 out of 1 (10%): ten times worse
The circle becomes a very thin ellipse: 2 wide on each side, only 0.2 tall. Undoing it must stretch the thin direction by 5. That is where errors grow.

A nearly singular matrix is much worse:

A = 1111.001: σ₁ ≈ 2, σ₂ ≈ 0.0005, condition number ≈ 4000
A 0.1% change in b can change x by up to 4000 × 0.1% = 400%

Keep reading with the full course

Finish lesson 8 and you will be able to: compress an image and keep only what matters.

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 · An invertible matrix

A = 2004: A⁺ = ½00¼ = A⁻¹. Condition number 4/2 = 2: very safe.

Exercise Solve Ax = b for this singular A with the pseudoinverse. Edit the code and press Run.
slide_6.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