Cheatsheet: Cramer's rule
The rule
Section titled “The rule”To solve M · v = b (M invertible), each coordinate is a ratio of determinants:
x = det(M with first column replaced by b) / det(M)y = det(M with second column replaced by b) / det(M)General n by n: the i-th unknown = det(M with i-th column replaced by b) / det(M).
Why it works (the derivation)
Section titled “Why it works (the derivation)”- The parallelogram spanned by
[x, y]andj-hathas signed areax(base 1, height x). - Apply
M: areas scale bydet(M), so the new area isdet(M) · x. - The transformed parallelogram is spanned by
band the second column ofM, so its area isdet([b | second column]). - Equate:
det(M) · x = det([b | second column]), sox = det([b | second column]) / det(M). - The same argument with
i-hatgivesy.
A coordinate is a signed area; transformations scale area by the determinant. That is the whole idea.
Needs det(M) != 0
Section titled “Needs det(M) != 0”Dividing by det(M) requires it to be nonzero. det(M) = 0 is the collapsed case (no unique solution); the division by zero is the rule honestly reporting that.
Worked examples
Section titled “Worked examples”| System | det(M) | x | y |
|---|---|---|---|
[[2,1],[1,1]]·v = [3,2] | 1 | det([[3,1],[2,1]])/1 = 1 | det([[2,3],[1,2]])/1 = 1 |
[[3,-1],[1,2]]·v = [7,0] | 7 | det([[7,-1],[0,2]])/7 = 2 | det([[3,7],[1,0]])/7 = -1 |
[[2,4],[1,2]]·v = [3,2] | 0 | undefined | undefined (no unique solution) |
First system matches the inverses lesson’s [1, 1]. Checks: 2(1)+1=3, 1+1=2; 3(2)-(-1)=7, 2+2(-1)=0.
Why it matters for AI (honest)
Section titled “Why it matters for AI (honest)”Rarely used in practice; iterative solvers and Gaussian elimination are faster for real systems. Cramer’s value is conceptual: an explicit, geometrically-derived solution formula. It closes the solve-the-system question from the inverses lesson.
Pitfalls to dodge
Section titled “Pitfalls to dodge”- Replacing the wrong column. For
xreplace column 1; foryreplace column 2. - Forgetting to divide by det(M). The answer is a ratio; the denominator is the original determinant.
- Using it when det(M) = 0. No unique solution; the division by zero is the signal.
- Using it on large systems. Determinant-per-unknown is slow; use elimination or an iterative solver.
The one-line version
Section titled “The one-line version”Each unknown is the determinant of the matrix with its column swapped for the target, over the determinant of the matrix, because a coordinate is an area and transformations scale area by the determinant.