Cramer's rule
The inverse of a matrix solves a whole system at once. Is there a formula that gives one unknown by itself, straight from the coefficients?
Where you are 12 in Matrices
When you reach for it
A square linear system with exactly one solution can be solved by row reduction or, as in Inverse of a 2 by 2 matrix, and solving with it, by X = A^{-1}B. Cramer’s rule writes each unknown on its own as a ratio of two determinants. You reach for it when you want one unknown and not the others, when a coefficient is a letter such as k and you want the answer as a formula in k, and for small systems with awkward numbers, where it avoids fractions until the last step.
The procedure
Two equations
Take the system
and form three determinants. D is the determinant of the coefficient matrix. D_x is the same determinant with the x column replaced by the constants e, f, and D_y has the y column replaced instead:
If D \neq 0, the system has exactly one solution, and
Why it is true. With D \neq 0 the coefficient matrix A has the inverse \displaystyle \frac{1}{D}\begin{bmatrix} d & -b \\ -c & a \end{bmatrix}, so the only solution is
and de - bf is exactly D_x, while af - ce is exactly D_y.
The column picture
There is a second reason, and it is the one that grows to three equations. Write the columns of A as \mathbf{c}_1 = \langle a, c \rangle and \mathbf{c}_2 = \langle b, d \rangle, and the constants as \mathbf{k} = \langle e, f \rangle. The system says x\mathbf{c}_1 + y\mathbf{c}_2 = \mathbf{k}. Put that into D_x, whose columns are \mathbf{k} and \mathbf{c}_2:
So every solution satisfies D \cdot x = D_x, whatever D is. The figure shows it for 2x + y = 7, x + 3y = 6, whose solution is (3, 1). Adding y\mathbf{c}_2 to a side slides it along the other side \mathbf{c}_2, which leaves the area alone; multiplying \mathbf{c}_1 by x multiplies the height above \mathbf{c}_2, and with it the area, by x.
Three equations
For three equations in x, y, z with coefficient matrix A, let D = \det A and let D_x, D_y, D_z be \det A with column 1, 2 or 3 replaced by the constants. If D \neq 0,
The column argument carries over. Each of the six products in a 3 \times 3 determinant uses exactly one entry from each column, so the determinant splits over a sum in one column and lets a number factor out of one column; and a determinant with two equal columns is 0 (both facts are developed in Properties of determinants: row operations, products, transposes). If \mathbf{k} = x\mathbf{c}_1 + y\mathbf{c}_2 + z\mathbf{c}_3, then
because the second and third pieces each have a repeated column. When D \neq 0 the matrix A is invertible (Finding an inverse by row reducing A next to I), so there is exactly one solution, and the equation D \cdot x = D_x names it.
When D is zero
If D = 0 the rule does not apply: it would divide by zero, and the coefficient matrix has no inverse, so the system has no solution or infinitely many, never exactly one. The equation D \cdot x = D_x still holds for any solution, so
- if D = 0 and any one of D_x, D_y, D_z is not 0, there is no solution, since a solution would make 0 = D_x \neq 0;
- if D = 0 and all of them are 0, the determinants say nothing more, and row reduction decides between no solution and infinitely many.
Choosing a method
For two equations, Cramer’s rule is three 2 \times 2 determinants and two divisions, as quick as anything. For one unknown of three it is two 3 \times 3 determinants. With a letter in the coefficients it hands you the solution as a formula and shows, through D = 0, exactly which values of the letter are trouble. For all three unknowns of a 3 \times 3 system it takes four 3 \times 3 determinants, and one row reduction is usually less work; for four or more equations row reduction wins by far.
Worked examples
Two equations with integer answers
Solve 5x + 3y = -1, 2x - 4y = 10.
SolutionThe coefficient determinant comes first, since it decides whether the rule applies:
It is not 0. Replace the x column, then the y column, by the constants -1, 10:
So \displaystyle x = \frac{-26}{-26} = 1 and \displaystyle y = \frac{52}{-26} = -2. Check. 5 - 6 = -1 and 2 + 8 = 10.
Fractions only at the end
Solve 3x + 7y = 2, 4x + 2y = 5.
SolutionSo \displaystyle x = \frac{31}{22} and \displaystyle y = -\frac{7}{22}. Every step before the last was integer arithmetic. Check.
Three equations
Solve
Expand each determinant along row 1 with the signs +, -, +.
Replacing column 1 by the constants -3, 13, 2:
In the same way, with column 2 and then column 3 replaced,
So \displaystyle x = \frac{-20}{-20} = 1, \displaystyle y = \frac{40}{-20} = -2 and \displaystyle z = \frac{-60}{-20} = 3. Check in the second equation: 1 + 6 + 6 = 13. Four 3 \times 3 determinants is real work; this is the case where row reduction competes.
Only one unknown is wanted
Ashwin, Keerthi and Manoj each restock the boathouse with oars, life jackets and seat cushions. Ashwin’s order of 2 oars, 3 life jackets and 4 cushions costs 153 dollars; Keerthi’s 1 oar, 4 life jackets and 2 cushions costs 114 dollars; Manoj’s 3 oars, 1 life jacket and 5 cushions costs 168 dollars. What does one life jacket cost?
SolutionWith prices o, j, c in dollars the orders say 2o + 3j + 4c = 153, o + 4j + 2c = 114 and 3o + j + 5c = 168. Only j is asked for, so only D and D_j are needed.
So \displaystyle j = \frac{-75}{-5} = 15: a life jacket costs 15 dollars. Two determinants answered the question; the other two prices were never needed.
A letter in the coefficients
Solve kx + 2y = 1, 2x + ky = 3 for x and y in terms of k, and say what happens at the values of k where the rule fails.
SolutionFor every k except 2 and -2,
At k = 2, D = 0 but D_x = -4 \neq 0, so there is no solution: the equations are 2x + 2y = 1 and 2x + 2y = 3, two parallel lines. At k = -2, D_x = -8 \neq 0, so again no solution: -2x + 2y = 1 and 2x - 2y = 3 are parallel too. Elimination would have needed a separate case for every value that makes a pivot zero; the formula shows them all at once.
When D is zero
Decide how many solutions each system has.
The two systems share their coefficients, and
so Cramer’s rule gives no solution formula for either. For the second system, replacing column 1 by 3, 0, 5 gives D_x = 3(-3) - 1(0 - 5) + 2(0 + 5) = 6, which is not 0, so it has no solution. For the first, D_x, D_y and D_z all come out 0, which settles nothing, so row reduce. R_2 - 2R_1 \to R_2 and R_3 - 3R_1 \to R_3 both give the row 0, -3, -3 \mid -6, and then R_3 - R_2 \to R_3 gives 0, 0, 0 \mid 0. The remaining equations are y + z = 2 and x + y + 2z = 3, so with z = t any real number,
infinitely many solutions. In the second system the same steps end in 0, 0, 0 \mid 2, the equation 0 = 2, agreeing with D_x \neq 0.
Boundaries
- Square systems only: as many equations as unknowns. A determinant exists only for a square matrix.
- D \neq 0 is required. When D = 0 there is never exactly one solution; a nonzero D_x, D_y or D_z means none, and when they are all zero row reduction decides.
- All zero determinants do not mean infinitely many. Exercise 16 has D = D_x = D_y = D_z = 0 and no solution at all.
- The constants replace a column, never a row, and they go in the column of the unknown being found.
- Equations in standard form first: every variable on the left in the same order, every constant on the right, with a 0 written for a missing variable.
- It does not scale. Each larger size needs more determinants, each far more costly, so beyond three equations row reduction is the practical method.
Where this goes next
Determinants by cofactor expansion computes the determinants Cramer’s rule needs at any size, and Properties of determinants: row operations, products, transposes proves the column facts the 3 \times 3 argument used. The column picture, a determinant as the area of the parallelogram two columns span, returns in The cross product, where the same parallelogram is measured by a cross product, and What the determinant means makes area and volume scaling precise.
Exercises
Two equations
Solve with Cramer’s rule, or show the rule does not apply and decide the system.
- 3x + 2y = 11, x - 4y = 13
- 6x - 5y = 1, 4x + 3y = 7
- 2x + 5y = 3, 7x - 3y = 4
- \displaystyle \frac{1}{2}x + \frac{1}{3}y = 1, x - y = 7
- 4x - 6y = 5, -6x + 9y = 2
Three equations
- x + y + z = 6, 2x - y + 3z = 9, x + 2y - z = 2
- 3x - y + 2z = 4, x + 4y - z = 3, 2x + y + 3z = 1
- Find only y: 2x + y + 3z = 1, x - 2y + z = 0, 4x + 3y - 2z = 5
- Show that D = 0 for x + 2y - z = 1, 2x + 4y - 2z = 3, x - y + z = 0, then decide whether it has no solution or infinitely many.
Letters and applications
- Solve x + ky = 2, kx + 4y = 4 in terms of k, and decide the system at each k where D = 0.
- Solve x + 2y = p, 3x + 5y = q for x and y in terms of p and q.
- Keerthi buys 3 dock ropes and 2 buoys for 27 dollars; Manoj buys 5 dock ropes and 4 buoys for 49 dollars. Find the price of one dock rope.
- The parabola y = ax^2 + bx + c passes through (1, 2), (2, 7) and (-1, 4). Find only a.
Reasoning
- Show, in the way the procedure showed D \cdot x = D_x, that every solution of a two-equation system satisfies D \cdot y = D_y.
- Derive \displaystyle x = \frac{D_x}{D} for two equations by elimination: multiply the first equation by d and the second by b, and subtract.
- Show that x + y + z = 1, x + y + z = 2, x + y + z = 3 has D = D_x = D_y = D_z = 0 and no solution.
- Ashwin wants to solve four equations in four unknowns by Cramer’s rule. How many 4 \times 4 determinants does he need, and why is row reduction less work?
- A two-equation system has integer coefficients and constants and D = 1 or D = -1. Explain why its solution is a pair of integers.
- Explain, using D and D_x, why writing the two equations of a system in the other order cannot change x.
Answers
- (x, y) = (5, -2). D = -12 - 2 = -14, D_x = -44 - 26 = -70, D_y = 39 - 11 = 28.
- (x, y) = (1, 1). D = 18 + 20 = 38, D_x = 3 + 35 = 38, D_y = 42 - 4 = 38.
- \displaystyle (x, y) = \left(\frac{29}{41}, \frac{13}{41}\right). D = -6 - 35 = -41, D_x = -9 - 20 = -29, D_y = 8 - 21 = -13.
- (x, y) = (4, -3). \displaystyle D = -\frac{1}{2} - \frac{1}{3} = -\frac{5}{6}, \displaystyle D_x = -1 - \frac{7}{3} = -\frac{10}{3}, \displaystyle D_y = \frac{7}{2} - 1 = \frac{5}{2}, and \displaystyle -\frac{10}{3} \div \left(-\frac{5}{6}\right) = 4, \displaystyle \frac{5}{2} \div \left(-\frac{5}{6}\right) = -3.
- No solution. D = 36 - 36 = 0 and D_x = 45 + 12 = 57 \neq 0.
- (x, y, z) = (1, 2, 3). D = 5, D_x = 5, D_y = 10, D_z = 15.
- (x, y, z) = (2, 0, -1). D = 39 + 5 - 14 = 30, D_x = 60, D_y = 0, D_z = -30.
- \displaystyle y = \frac{11}{41}. D = 2(1) - 1(-6) + 3(11) = 41 and D_y = 2(-5) - 1(-6) + 3(5) = 11.
- No solution. The second row of coefficients is twice the first, so D = 0; D_x = 1(2) - 2(3) - 1(-3) = -1 \neq 0. Directly, twice the first equation says 2x + 4y - 2z = 2, not 3.
- D = 4 - k^2, D_x = 8 - 4k, D_y = 4 - 2k, so for k \neq \pm 2, \displaystyle x = \frac{4}{k + 2} and \displaystyle y = \frac{2}{k + 2} after cancelling 2 - k. At k = 2 all three are 0, and 2x + 4y = 4 is twice x + 2y = 2: infinitely many solutions. At k = -2, D_x = 16 \neq 0: no solution.
- x = 2q - 5p, y = 3p - q. D = 5 - 6 = -1, D_x = 5p - 2q, D_y = q - 3p.
- 5 dollars. With r and b the prices, 3r + 2b = 27 and 5r + 4b = 49; D = 12 - 10 = 2 and D_r = 108 - 98 = 10.
- a = 2. The points give a + b + c = 2, 4a + 2b + c = 7, a - b + c = 4; D = 3 - 3 - 6 = -6 and D_a = 2(3) - 1(3) + 1(-15) = -12.
- With \mathbf{k} = x\mathbf{c}_1 + y\mathbf{c}_2, the determinant D_y is \begin{vmatrix} a & xa + yb \\ c & xc + yd \end{vmatrix}, which is a(xc + yd) - (xa + yb)c. That equals x(ac - ac) + y(ad - bc), and so yD.
- The left sides give d(ax + by) - b(cx + dy) and the right sides de - bf. The y terms cancel, since bdy - bdy = 0, leaving (ad - bc)x = de - bf, that is D \cdot x = D_x; divide by D \neq 0.
- Every column of A is \langle 1, 1, 1 \rangle, so D has equal columns, and each of D_x, D_y, D_z keeps two of those equal columns, so all four are 0. A single number x + y + z cannot equal 1 and 2, so there is no solution.
- Five: D and one for each unknown. Each 4 \times 4 determinant has 24 products of four entries, 120 products in all. Row reduction works on one 4 \times 5 matrix: clearing below the pivots updates 12 + 6 + 2 = 20 entries, then a short back substitution.
- D_x and D_y are built from integers by multiplying and subtracting, so they are integers, and dividing an integer by 1 or -1 gives an integer.
- Swapping the equations swaps the rows of every determinant, and \begin{vmatrix} c & d \\ a & b \end{vmatrix} = bc - ad = -D. So D and D_x both change sign, and their ratio does not change.