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.
The solution is .
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 and . The coefficients are 3 and −4; their least common multiple is 12:
The recipe:
- Line up the equations as .
- Choose a variable and multiply the equations so its coefficients become opposites (or equal).
- Add (or subtract) to eliminate it, and solve for the remaining variable.
- Substitute back into one original equation to find the other variable.
- Check in both original equations.
Tip: Eliminate whichever variable needs the smallest multipliers. In the system above, eliminating would need and , giving ; eliminating gave . 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 |
|---|---|---|
| (always true) | the equations describe the same line: infinitely many solutions | and |
| (never true) | parallel lines: no solution | and |
In the second row, gives ; subtracting it from leaves .
Elimination in code
The steps are mechanical, so a program can perform them. Using Fraction keeps every number exact, just like on paper:
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 . Same equation, same answer. (This short version divides by ax and b1, so it fails when the solution is not unique or when ; 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?
Divide the first equation by 2 and the second by 8 to get and . Subtract: , so and .
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 and by elimination.
Answer
, .
Solution
Exercise 2: Scale one equation
Solve and .
Answer
, .
Solution
Exercise 3: Scale both
Solve and .
Answer
, .
Solution
Eliminate with multipliers 2 and 3:
import numpy as np
print(np.linalg.solve([[3, 4], [2, -5]], [10, 22]))[ 6. -2.]
Exercise 4: Which case?
Use elimination on and . What happens, and what does it mean?
Answer
Everything cancels to : the equations describe the same line, so there are infinitely many solutions (all points with ).
Solution
Both equations are multiples of (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
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 from and , which multipliers work?
- Multiply the first by 7 and the second by 2
- Multiply the first by 2 and the second by 3, then add
- Multiply the first by 3 and the second by 2, then add
- No multipliers are needed
Elimination leaves the statement . What does the system have?
- No solution
- Exactly one solution,
- Infinitely many solutions
- Exactly two solutions
Why may you multiply an equation by 3 before adding it to another?
- Because it changes the solution in a useful way
- Because multiplying both sides by a non-zero number keeps the same solutions
- Because only odd numbers are allowed
- You may not; it is a common mistake