Three Unknowns by Elimination
With three unknowns you need three equations, and elimination works in two rounds: first use the equations in pairs to remove one variable, which leaves a system; then solve that system as before. This lesson walks through the steps and shows how a program does the same bookkeeping.
The plan
A linear equation in , and , such as , describes a flat plane in 3D space. A solution of a system is a point on all three planes. Typically three planes meet in exactly one point, the way two walls and a floor meet in a corner.
The strategy:
- Pick a variable to eliminate (the one that cancels most easily).
- Combine equations (1) and (2) to eliminate it, giving equation (A).
- Combine (1) and (3), or (2) and (3), to eliminate the same variable, giving equation (B).
- Solve the system (A), (B) with elimination.
- Substitute both values into an original equation to find the third variable.
- Check in all three original equations.
A worked example
has coefficients 1, 1 and −1, so adding (3) to either of the others removes it:
Now a system. Multiply (B) by 3 and subtract (A):
Check every equation:
The solution is the point .
Tip: Number every equation you create and write down which ones you combined, as in "(1) + (3)". A system has enough steps that unlabelled work quickly becomes impossible to check.
A common mistake
Steps 2 and 3 must eliminate the same variable. If (A) loses but (B) loses , you have two equations in different pairs of unknowns ( and ) and the step does not work. Also, (A) and (B) must come from different pairs of equations; combining (1) and (3) twice only gives a multiple of the same equation.
When there is no single point
Three planes do not always meet in one point. Elimination shows it the same way as in two unknowns:
| Result during elimination | Geometry | Solutions |
|---|---|---|
| unique values for , , | three planes through one point | one |
| a false statement such as | no common point (parallel planes, or a "tent" of three planes) | none |
| a true statement that leaves a variable free | planes share a whole line (or are the same plane) | infinitely many |
Elimination in code
Computers do not choose clever combinations; they follow a fixed order. Use row 1 to clear from the rows below it, then row 2 to clear below it. What remains is a triangular system, solved from the bottom up:
from fractions import Fraction as F
rows = [[1, 1, 1, 4], # each row: a, b, c | d for ax + by + cz = d
[2, -1, 1, 8],
[1, 2, -1, -3]]
rows = [[F(v) for v in r] for r in rows]
for col in range(3): # forward elimination
pivot = rows[col]
for r in rows[col + 1:]:
factor = r[col] / pivot[col]
for k in range(4):
r[k] -= factor * pivot[k]
for r in rows:
print([str(v) for v in r])
x = [F(0)] * 3 # back substitution
for i in (2, 1, 0):
s = sum(rows[i][j] * x[j] for j in range(i + 1, 3))
x[i] = (rows[i][3] - s) / rows[i][i]
print("x, y, z =", [str(v) for v in x])['1', '1', '1', '4']
['0', '-3', '-1', '0']
['0', '0', '-7/3', '-7']
x, y, z = ['2', '-1', '3']
The bottom row says , so ; the middle row then gives , so ; the top row gives . Same answer, different route. This orderly version is called Gaussian elimination. It is how libraries such as NumPy solve systems with thousands of unknowns, with one extra trick: they swap rows so the pivot is never zero or tiny. The full algorithm is in Gaussian Elimination; the same steps written on a grid of numbers are The Matrix Method.
In software
Three-unknown systems appear when three constraints must hold at once:
- Colour mixing: which amounts of three pigments (or three LED channels) produce a target colour with given red, green and blue values?
- Budgets with three resources: CPU, memory and storage across three server types.
- Fitting a parabola: the curve through three measured points gives three linear equations in , , . Exercise 4 below does exactly this.
Exercises
Exercise 1: Warm-up
Solve , , .
Answer
, , .
Solution
Exercise 2: Full elimination
Solve , , .
Answer
, , .
Solution
Eliminate , which has coefficients 1, −1 and 2:
from sympy import symbols, solve
x, y, z = symbols("x y z")
print(solve([2*x + y - z - 3, x - y + 2*z - 5, 3*x + 2*y + z - 10], [x, y, z])){x: 2, y: 1, z: 2}
Exercise 3: Code it
Solve with numpy.linalg.solve: , , .
Answer
, , .
Solution
import numpy as np
A = np.array([[1, 2, 3], [2, 1, 1], [3, 1, 2]], dtype=float)
b = np.array([14, 7, 11], dtype=float)
print(np.round(np.linalg.solve(A, b), 6))[1. 2. 3.]
Check: ✓, ✓, ✓.
Exercise 4: A parabola through three points
Find , and so that passes through , and .
Answer
, , , so .
Solution
Each point gives one equation in , , :
Check: gives ✓.
Test yourself
After the first round of eliminating from a system, what do you have?
- One equation in
- Two equations in and
- Three equations in , and
- The final answer
What does a single linear equation in , and describe geometrically?
- A point
- A line
- A plane
- A sphere
Gaussian elimination turns a system into which shape before back substitution?
- Triangular: each row has fewer unknowns than the one above
- Diagonal only
- Circular
- A single equation