Cramer's Rule

Here's a small magic trick. Give me a square system of linear equations — the same number of equations as unknowns — and I'll write down the answer for any single unknown you like using nothing but determinants. No back-substitution, no elimination, no chasing variables around the page. Just two determinants and a division. That trick is Cramer's rule.

Take the system

\begin{aligned} 2x + y &= 5 \\ x - 3y &= -1 \end{aligned}

and package it as a matrix equation A\mathbf{x} = \mathbf{b}, where the columns of A are the coefficient vectors and \mathbf{b} is the right-hand side:

A = \begin{bmatrix} 2 & 1 \\ 1 & -3 \end{bmatrix}, \qquad \mathbf{b} = \begin{bmatrix} 5 \\ -1 \end{bmatrix}.

Cramer's rule says: to find x, take the determinant of A — but with its first column swapped out for \mathbf{b} — and divide by \det A. To find y, swap out the second column instead. Every unknown is a ratio of two determinants.

The rule, in general

Suppose A\mathbf{x} = \mathbf{b} is an n \times n system and \det A \neq 0. Then the system has exactly one solution, and its i-th component is

x_i = \frac{\det A_i}{\det A},

where A_i is the matrix A with its i-th column replaced by the vector \mathbf{b}. That single sentence is the whole method. Everything left is bookkeeping: form n+1 matrices (A itself, plus one column-swapped copy per unknown), take their determinants, and divide.

The denominator is always the same — \det A — so the whole solution lives or dies on that one number. If \det A = 0 the formula divides by zero and simply refuses to answer; that's not a bug, it's the rule telling you the system doesn't have a single tidy solution (more on that below).

Why it's a ratio of areas

The formula can look like a rabbit pulled from a hat, but in two dimensions it's pure geometry. Recall the headline fact about determinants: \det A is the signed area of the parallelogram spanned by the columns of A. Call those columns \mathbf{a}_1 and \mathbf{a}_2.

Now the whole point of solving A\mathbf{x} = \mathbf{b} is to write \mathbf{b} as a blend of those two columns:

\mathbf{b} = x\,\mathbf{a}_1 + y\,\mathbf{a}_2.

Feed that into the numerator determinant for x, which is the area of the parallelogram spanned by \mathbf{b} and \mathbf{a}_2:

\det A_1 = \det[\,\mathbf{b}\ \ \mathbf{a}_2\,] = \det[\,x\,\mathbf{a}_1 + y\,\mathbf{a}_2\ \ \mathbf{a}_2\,] = x\,\det[\,\mathbf{a}_1\ \ \mathbf{a}_2\,] = x\,\det A.

The y\,\mathbf{a}_2 piece contributes nothing — a parallelogram with two parallel sides is squashed flat, area zero — so only the x\,\mathbf{a}_1 part survives, scaling the original area by exactly x. Divide by \det A and you get x = \det A_1 / \det A. The unknown x is literally the ratio by which swapping in \mathbf{b} rescaled the area — a measure of "how much of \mathbf{b} points along the \mathbf{a}_1 direction." Move the vectors below and watch the two areas, and their ratio, breathe.

Worked example 1 — the 2×2 system

Back to our opening system. First the denominator, the area of the coefficient parallelogram:

\det A = \det\begin{bmatrix} 2 & 1 \\ 1 & -3 \end{bmatrix} = (2)(-3) - (1)(1) = -6 - 1 = -7.

It's non-zero, so a unique solution exists and we may proceed. For x, replace the first column of A with \mathbf{b} = \begin{bmatrix} 5 \\ -1 \end{bmatrix}:

x = \frac{\det A_1}{\det A} = \frac{\det\begin{bmatrix} \mathbf{5} & 1 \\ \mathbf{-1} & -3 \end{bmatrix}}{-7} = \frac{(5)(-3) - (1)(-1)}{-7} = \frac{-15 + 1}{-7} = \frac{-14}{-7} = 2.

For y, put \mathbf{b} in the second column instead and keep the same denominator:

y = \frac{\det A_2}{\det A} = \frac{\det\begin{bmatrix} 2 & \mathbf{5} \\ 1 & \mathbf{-1} \end{bmatrix}}{-7} = \frac{(2)(-1) - (5)(1)}{-7} = \frac{-2 - 5}{-7} = \frac{-7}{-7} = 1.

So (x, y) = (2, 1). Sanity check it against the original equations: 2(2) + 1 = 5 ✓ and 2 - 3(1) = -1 ✓. Two determinants and a shared denominator, and we never once eliminated a variable.

Worked example 2 — one unknown from a 3×3 system

The real charm of Cramer's rule shows when you want just one unknown out of many — you can get it without solving for the others. Consider

\begin{aligned} x + 2y + z &= 6 \\ 2x + \phantom{2}y + 3z &= 13 \\ x - \phantom{2}y + \phantom{3}z &= 2 \end{aligned} \qquad A = \begin{bmatrix} 1 & 2 & 1 \\ 2 & 1 & 3 \\ 1 & -1 & 1 \end{bmatrix},\quad \mathbf{b} = \begin{bmatrix} 6 \\ 13 \\ 2 \end{bmatrix}.

Expand \det A along the top row (each entry times the determinant of the 2×2 that survives when you cross out its row and column, with the checkerboard +\,-\,+ signs):

\det A = 1\begin{vmatrix} 1 & 3 \\ -1 & 1 \end{vmatrix} - 2\begin{vmatrix} 2 & 3 \\ 1 & 1 \end{vmatrix} + 1\begin{vmatrix} 2 & 1 \\ 1 & -1 \end{vmatrix} = 1(4) - 2(-1) + 1(-3) = 4 + 2 - 3 = 3.

Say we only care about z. Replace the third column of A with \mathbf{b} and take that determinant:

\det A_3 = \begin{vmatrix} 1 & 2 & 6 \\ 2 & 1 & 13 \\ 1 & -1 & 2 \end{vmatrix} = 1\begin{vmatrix} 1 & 13 \\ -1 & 2 \end{vmatrix} - 2\begin{vmatrix} 2 & 13 \\ 1 & 2 \end{vmatrix} + 6\begin{vmatrix} 2 & 1 \\ 1 & -1 \end{vmatrix} = 1(15) - 2(-9) + 6(-3) = 15 + 18 - 18 = 15. z = \frac{\det A_3}{\det A} = \frac{15}{3} = 5.

(If you're curious, the full solution is (x, y, z) = (1, 0, 5) — but Cramer's rule handed us z directly, without ever pinning down x or y. That "reach in and grab one unknown" power is exactly why the rule stays useful in symbolic algebra, physics derivations, and proofs.)

Cramer's rule only works when \det A \neq 0. That's the case of a genuinely unique solution. If \det A = 0, every one of Cramer's fractions has a 0 in the denominator, and the rule says nothing: the system might have no solution at all, or it might have infinitely many, and Cramer's rule can't tell you which. Don't try to patch it — reach for Gaussian elimination instead, which handles those degenerate cases gracefully.

And it's a lovely formula but a terrible algorithm. Solving an n \times n system needs n+1 determinants, and computing a determinant the "textbook" cofactor way costs on the order of n \cdot n! operations — astronomically slow, and numerically fragile (round-off errors pile up badly) for anything but the smallest systems. For a 2×2 or 3×3, or when you want a clean symbolic answer, Cramer's rule is delightful. Beyond that — big systems, floating-point numbers, real computation — use Gaussian elimination, which is O(n^3) and stable. Cramer's rule is a beautiful idea, not a workhorse.

The rule is named for the Swiss mathematician Gabriel Cramer, who published it in 1750 in a book about algebraic curves — he needed to pin down the coefficients of a curve forced to pass through a given set of points, which is exactly a linear system in disguise. Fittingly, the Scottish mathematician Colin Maclaurin had worked out essentially the same determinant recipe a few years earlier, so the "who was first" question is itself a little tangled.

What makes it endure isn't speed — it's that the answer comes out as a single closed-form expression. In physics and engineering you often don't want a number, you want a formula showing how the unknown depends on the inputs (currents in a circuit as functions of the resistances, say). Cramer's rule hands you that dependency on a plate: each unknown is one determinant over another, symbols and all.