TExcelTAD
Home › Algebra › The Elimination Method

The Elimination Method

The elimination method solves a system by adding or subtracting the equations so that one unknown cancels out. What is left is an ordinary equation with one unknown, which you already know how to solve. It is the method computers use, too, in a more organised form called Gaussian elimination.

The idea

If two equations are true, their sum is true as well: equal things added to equal things give equal things. Pick the sum (or difference) that makes one variable disappear.

3x+2y=165x−2y=0add the equations: +2y and −2y cancel8x=16→ x=2\begin{array}{rcll} 3x + 2y &=& 16 & \\ 5x - 2y &=& 0 & \text{add the equations: } +2y \text{ and } -2y \text{ cancel} \\ \hline 8x &=& 16 & \to\ x = 2 \end{array}
back into the first:3⋅2+2y=16→2y=10→y=5check the second:5⋅2−2⋅5=0 ✓\begin{aligned} \text{back into the first:} &\quad 3 \cdot 2 + 2y = 16 \to 2y = 10 \to y = 5 \\ \text{check the second:} &\quad 5 \cdot 2 - 2 \cdot 5 = 0\ \checkmark \end{aligned}

The solution is (2,5)(2, 5).

Scaling first

Usually no variable cancels straight away. Then you multiply one or both equations by a number first. Multiplying both sides of an equation by the same non-zero number does not change its solutions.

Solve 2x+3y=122x + 3y = 12 and 5x−4y=75x - 4y = 7. The yy coefficients are 3 and −4; their least common multiple is 12:

(1)×4:8x+12y=48(2)×3:15x−12y=21add:23x=69→x=3(1):2⋅3+3y=12→3y=6→y=2check (2):5⋅3−4⋅2=15−8=7 ✓\begin{aligned} (1) \times 4: &\quad 8x + 12y = 48 \\ (2) \times 3: &\quad 15x - 12y = 21 \\ \text{add:} &\quad 23x = 69 \to x = 3 \\ (1): &\quad 2 \cdot 3 + 3y = 12 \to 3y = 6 \to y = 2 \\ \text{check } (2): &\quad 5 \cdot 3 - 4 \cdot 2 = 15 - 8 = 7\ \checkmark \end{aligned}

The recipe:

  1. Line up the equations as ax+by=cax + by = c.
  2. Choose a variable and multiply the equations so its coefficients become opposites (or equal).
  3. Add (or subtract) to eliminate it, and solve for the remaining variable.
  4. Substitute back into one original equation to find the other variable.
  5. Check in both original equations.

Tip: Eliminate whichever variable needs the smallest multipliers. In the system above, eliminating xx would need ×5\times 5 and ×2\times 2, giving 10x10x; eliminating yy gave 12y12y. Either works; small numbers just mean fewer slips.

What a failed elimination tells you

Sometimes both variables vanish at once. That is not a mistake: it is the system telling you which case you are in (see Systems of Equations).

After eliminating Meaning Example
0=00 = 0 (always true) the equations describe the same line: infinitely many solutions x−2y=3x - 2y = 3 and 3x−6y=93x - 6y = 9
0=50 = 5 (never true) parallel lines: no solution x−2y=3x - 2y = 3 and 3x−6y=143x - 6y = 14

In the second row, (1)×3(1) \times 3 gives 3x−6y=93x - 6y = 9; subtracting it from 3x−6y=143x - 6y = 14 leaves 0=50 = 5.

Elimination in code

The steps are mechanical, so a program can perform them. Using Fraction keeps every number exact, just like on paper:

python · try it yourself
from fractions import Fraction as F

def eliminate(eq1, eq2):
    """Each equation is (a, b, c), meaning a·x + b·y = c."""
    a1, b1, c1 = map(F, eq1)
    a2, b2, c2 = map(F, eq2)
    # multiply eq1 by b2 and eq2 by b1, then subtract: y cancels
    ax = a1 * b2 - a2 * b1
    cx = c1 * b2 - c2 * b1
    print(f"after eliminating y: {ax}x = {cx}")
    x = cx / ax
    y = (c1 - a1 * x) / b1          # back-substitute into eq1
    return x, y

x, y = eliminate((2, 3, 12), (5, -4, 7))
print("x =", x, " y =", y)
after eliminating y: -23x = -69
x = 3  y = 2

The program multiplied by 3 and −4 instead of 4 and 3, so it got −23x=−69-23x = -69. Same equation, same answer. (This short version divides by ax and b1, so it fails when the solution is not unique or when b1=0b_1 = 0; real solvers check for that.)

In software: resource budgets

A team runs its build farm on two machine types. A small machine has 2 vCPUs and 8 GB of memory; a large one has 8 vCPUs and 16 GB. The budget is exactly 40 vCPUs and 112 GB. How many of each type use the budget completely?

{2s+8l=40(vCPUs)8s+16l=112(GB of memory)\begin{cases} 2s + 8l = 40 & \text{(vCPUs)} \\ 8s + 16l = 112 & \text{(GB of memory)} \end{cases}

Divide the first equation by 2 and the second by 8 to get s+4l=20s + 4l = 20 and s+2l=14s + 2l = 14. Subtract: 2l=62l = 6, so l=3l = 3 and s=14−6=8s = 14 - 6 = 8.

python · try it yourself
import numpy as np

A = np.array([[2, 8], [8, 16]], dtype=float)   # coefficients
b = np.array([40, 112], dtype=float)            # budgets
s, l = np.linalg.solve(A, b)
print(f"small = {s:.0f}, large = {l:.0f}")
print("vCPUs used:", int(A[0] @ [s, l]), " GB used:", int(A[1] @ [s, l]))
small = 8, large = 3
vCPUs used: 40  GB used: 112

np.linalg.solve performs elimination for you (in floating point). The same pattern fits any "two resources, two products" question: ad budget and click targets, ingredients in two recipes, power and bandwidth in a network design. With more resources you get bigger systems, handled in Three Unknowns by Elimination and, in general, by Gaussian elimination in the linear algebra course.

Exercises

Exercise 1: Ready to add

Solve x+y=9x + y = 9 and x−y=3x - y = 3 by elimination.

Answer

x=6x = 6, y=3y = 3.

Solution
add:2x=12→x=6first:6+y=9→y=3check:6−3=3 ✓\begin{aligned} \text{add:} &\quad 2x = 12 \to x = 6 \\ \text{first:} &\quad 6 + y = 9 \to y = 3 \\ \text{check:} &\quad 6 - 3 = 3\ \checkmark \end{aligned}

Exercise 2: Scale one equation

Solve 4x+y=114x + y = 11 and 3x−2y=03x - 2y = 0.

Answer

x=2x = 2, y=3y = 3.

Solution
(1)×2:8x+2y=22(2):3x−2y=0add:11x=22→x=2(1):8+y=11→y=3check (2):6−6=0 ✓\begin{aligned} (1) \times 2: &\quad 8x + 2y = 22 \\ (2): &\quad 3x - 2y = 0 \\ \text{add:} &\quad 11x = 22 \to x = 2 \\ (1): &\quad 8 + y = 11 \to y = 3 \\ \text{check } (2): &\quad 6 - 6 = 0\ \checkmark \end{aligned}

Exercise 3: Scale both

Solve 3x+4y=103x + 4y = 10 and 2x−5y=222x - 5y = 22.

Answer

x=6x = 6, y=−2y = -2.

Solution

Eliminate xx with multipliers 2 and 3:

(1)×2:6x+8y=20(2)×3:6x−15y=66subtract:23y=−46→y=−2(1):3x−8=10→3x=18→x=6check (2):12+10=22 ✓\begin{aligned} (1) \times 2: &\quad 6x + 8y = 20 \\ (2) \times 3: &\quad 6x - 15y = 66 \\ \text{subtract:} &\quad 23y = -46 \to y = -2 \\ (1): &\quad 3x - 8 = 10 \to 3x = 18 \to x = 6 \\ \text{check } (2): &\quad 12 + 10 = 22\ \checkmark \end{aligned}
python · try it yourself
import numpy as np
print(np.linalg.solve([[3, 4], [2, -5]], [10, 22]))
[ 6. -2.]

Exercise 4: Which case?

Use elimination on 6x−9y=126x - 9y = 12 and 4x−6y=84x - 6y = 8. What happens, and what does it mean?

Answer

Everything cancels to 0=00 = 0: the equations describe the same line, so there are infinitely many solutions (all points with 2x−3y=42x - 3y = 4).

Solution
(1)×2:12x−18y=24(2)×3:12x−18y=24subtract:0=0\begin{aligned} (1) \times 2: &\quad 12x - 18y = 24 \\ (2) \times 3: &\quad 12x - 18y = 24 \\ \text{subtract:} &\quad 0 = 0 \end{aligned}

Both equations are multiples of 2x−3y=42x - 3y = 4 (divide the first by 3, the second by 2).

Exercise 5: A budget in code

A shop packs gift boxes. A basic box uses 1 kg of chocolate and 2 ribbons, a deluxe box uses 3 kg and 3 ribbons. There are 36 kg of chocolate and 45 ribbons. Set up the system and solve it with np.linalg.solve. How many boxes of each kind use everything up?

Answer

9 basic and 9 deluxe boxes.

Solution
b+3d=36(chocolate)2b+3d=45(ribbons)subtract the first from the second: b=9then 9+3d=36→d=9\begin{aligned} b + 3d &= 36 && \text{(chocolate)} \\ 2b + 3d &= 45 && \text{(ribbons)} \\ &\text{subtract the first from the second: } b = 9 \\ &\text{then } 9 + 3d = 36 \to d = 9 \end{aligned}
python · try it yourself
import numpy as np
b, d = np.linalg.solve([[1, 3], [2, 3]], [36, 45])
print(round(float(b)), round(float(d)))
9 9

Test yourself

To eliminate yy from 2x+3y=52x + 3y = 5 and 7x−2y=47x - 2y = 4, which multipliers work?

  1. Multiply the first by 7 and the second by 2
  2. Multiply the first by 2 and the second by 3, then add
  3. Multiply the first by 3 and the second by 2, then add
  4. No multipliers are needed

Elimination leaves the statement 0=00 = 0. What does the system have?

  1. No solution
  2. Exactly one solution, x=0x = 0
  3. Infinitely many solutions
  4. Exactly two solutions

Why may you multiply an equation by 3 before adding it to another?

  1. Because it changes the solution in a useful way
  2. Because multiplying both sides by a non-zero number keeps the same solutions
  3. Because only odd numbers are allowed
  4. You may not; it is a common mistake