Linear Algebra, Live
Strang §5.3 · Cramer's rule and inverses

Cramer's rule and the inverse from cofactors

Slide 6 built det A out of cofactors. Now cofactors pay off twice. Remember the café from lesson 2: a coffee and a croissant cost €5, a coffee and two croissants cost €7. Suppose you only want the price of the coffee. Cramer's rule gets it in one step, without finding the croissant first: put the prices 57 in place of the coffee's column, and divide that determinant by det A. Every unknown gets its own ratio like this. The same cofactors also give a formula for the whole inverse. Put all the cofactors Cᵢⱼ into one matrix C, the cofactor matrix; then A⁻¹ = Cᵀ / det A. Both are neat on paper, but slow for big systems.

Lesson 6 · slide 7Cramer's rule
xⱼ = det Bⱼ / det A    (Bⱼ = A with column j replaced by b)    A⁻¹ = Cᵀ / det A
Key ideas
  1. Cramer's rule: xⱼ = det Bⱼ / det A, where Bⱼ is A with its column j replaced by b.
  2. It needs det A ≠ 0, the same condition as for A⁻¹ to exist.
  3. The inverse: (A⁻¹)ᵢⱼ = Cⱼᵢ / det A. The indices swap: the cofactor matrix is transposed.
  4. For 2 by 2 this is exactly the formula from lesson 3.

The café, by Cramer's rule

Coffee x, croissant y: x + y = 5 and x + 2y = 7. So A = 1112 and b = 57.

det A = 1·2 − 1·1 = 1
coffee: x = det 5172 / 1 = (10 − 7) / 1 = 3   (b replaces column 1)
croissant: y = det 1517 / 1 = (7 − 5) / 1 = 2   (b replaces column 2)

Same answer as lesson 2: €3 and €2. The rule in general: xⱼ = det Bⱼ / det A, where Bⱼ is A with its column j replaced by b.

Why it works (2 by 2)

Call the two columns of A c₁ and c₂ (column 1 and column 2), so b = x₁c₁ + x₂c₂. Put b in column 1 and use the rules from slide 4 (they hold for columns, since det Aᵀ = det A, slide 5):

det [b c₂] = det [x₁c₁ + x₂c₂   c₂] = x₁ det [c₁ c₂] + x₂ det [c₂ c₂]
The last determinant has two equal columns, so it is 0
det B₁ = x₁ · det A,   so x₁ = det B₁ / det A

In pictures: the parallelogram of b and c₂ has x₁ times the area of the parallelogram of c₁ and c₂. The reason: b = x₁c₁ + x₂c₂, and the x₂c₂ part only slides the tip along the direction of c₂, which does not change the area (a shear, slide 4); what is left is x₁c₁, which multiplies the area by x₁. The same works for every column and every size.

A worked example

A = 2113,   b = 510,   det A = 6 − 1 = 5
B₁ = 51103: det = 15 − 10 = 5,   x₁ = 5/5 = 1
B₂ = 25110: det = 20 − 5 = 15,   x₂ = 15/5 = 3
Check: A13 = 2 + 31 + 9 = 510 ✓
Cramer's answer x = 13 as a walk: 1 step of column 1, then 3 steps of column 2, ends exactly on b = 510.

The inverse from cofactors

Column j of A⁻¹ solves Ax = (column j of I). Take b = 10. Then B₁ = 1a₁₂0a₂₂ has det a₂₂, which is the cofactor C₁₁. And B₂ = a₁₁1a₂₁0 has det −a₂₁, which is the cofactor C₁₂. So column 1 of A⁻¹ is C₁₁C₁₂ / det A. Row 1 of the cofactor matrix C (the matrix of all cofactors Cᵢⱼ, with Cᵢⱼ in row i, column j) became column 1 of A⁻¹. That is why C is transposed:

A⁻¹ = Cᵀ / det A
2 by 2: C = d−c−ba,   Cᵀ = d−b−ca,   A⁻¹ = d−b−ca / (ad − bc)

That is the 2 by 2 recipe from lesson 3 (swap, flip signs, divide by the determinant), now explained. With numbers, for the café matrix:

A = 1112, det A = 1  →  A⁻¹ = 2−1−11
A⁻¹(5, 7) = 10 − 7−5 + 7 = 32 ✓ the same prices

Keep reading with the full course

Finish lesson 6 and you will be able to: see a matrix as a move of the plane, and build one from where two arrows land.

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 · Cramer for another 2 by 2

x + 2y = 5,   3x + 4y = 6.

Show solutionHide solution
det A = 4 − 6 = −2
x = det 5264 / (−2) = (20 − 12)/(−2) = −4
y = det 1536 / (−2) = (6 − 15)/(−2) = 4.5
Check: −4 + 9 = 5 ✓,   −12 + 18 = 6 ✓
Exercise Fix B₂ (b goes into column 2) so that Cramer's rule solves Ax = b. Edit the code and press Run.
slide_7.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