Systems of Equations
A system of equations is two or more equations that must all be true at the same time. One equation with two unknowns has endless solutions; a second equation usually pins them down to a single pair. This lesson explains what a solution of a system is, how to check one, and why a system can have one, none or infinitely many solutions.
One equation is not enough
A school play sells adult tickets for €12 and child tickets for €7. On Friday it sold 20 tickets for €195. How many of each?
Call the number of adult tickets and the number of child tickets . The story gives two facts, so you get two equations:
Each equation alone allows many pairs. is true for , , and so on. Only a pair that makes both equations true answers the question. Such a pair is a solution of the system, and the equations written together, usually with a brace, form a system of linear equations (linear because every unknown appears only to the first power).
Because the ticket counts are whole numbers from 0 to 20, a program can simply try every pair:
solutions = []
for a in range(21):
c = 20 - a # the first equation fixes c once a is chosen
if 12 * a + 7 * c == 195: # does the money equation hold too?
solutions.append((a, c))
print("adult, child:", solutions)adult, child: [(11, 9)]
So 11 adult and 9 child tickets were sold. Check by hand: and . Brute force works here because there are only 21 candidates; the next lessons (elimination, substitution, determinants) solve any system without guessing.
Checking a solution
To check a candidate pair, substitute it into every equation. It is a solution only if all of them hold.
| System | Candidate | Equation 1 | Equation 2 | Solution? |
|---|---|---|---|---|
| , | ✓ | ✓ | yes | |
| , | ✓ | ✗ | no | |
| , | ✓ | ✓ | yes |
Tip: Always check your answer in the original equations, not in a rearranged version. A slip during rearranging would survive a check against the rearranged form.
One, none or infinitely many
The graph of a linear equation in two unknowns is a straight line (see Graphing Linear Equations). A solution of the system is a point that lies on both lines, so there are exactly three possibilities:
| Lines | Number of solutions | Example | What algebra shows |
|---|---|---|---|
| cross once | exactly one | , | a single pair |
| parallel, different | none (inconsistent) | , | a false statement such as |
| the same line | infinitely many (dependent) | , | a true statement such as |
Two straight lines cannot meet in exactly two points, so a linear system never has exactly two solutions. That changes once curves are involved: a line and a parabola can meet twice (you will see this in Solving Systems by Graphing).
SymPy solves systems exactly and reports all three cases clearly:
from sympy import symbols, Eq, solve
x, y = symbols("x y")
print(solve([Eq(x + y, 5), Eq(x - y, 1)], [x, y]))
print(solve([Eq(x + y, 5), Eq(x + y, 8)], [x, y]))
print(solve([Eq(x + y, 5), Eq(2*x + 2*y, 10)], [x, y])){x: 3, y: 2}
[]
{x: 5 - y}
The empty list means "no solution". The last answer means "any works, as long as ": a whole line of solutions.
In software
Systems of equations appear whenever several constraints must hold at once:
- Mixing and budgets. How many small and large servers fit a CPU budget and a memory budget? How much of two data sources gives a training set with exactly 30 % labelled examples? Each budget or target is one equation.
- Geometry in games. Where does a bullet's path cross a wall? Each line is an equation; the hit point solves the system.
- Fitting and balancing. Choosing two game parameters so that two playtest targets are met, or fitting a line through two measurements, is a system.
Large systems with thousands of unknowns (physics engines, circuit simulators, machine-learning models) are solved by exactly the methods of this chapter, organised as matrices. The full theory is in Linear Algebra.
Exercises
Exercise 1: Check the candidates
Which of , and solve the system , ?
Answer
Only .
Solution
Exercise 2: Write the system
A café sells muffins for €3 and cookies for €2. One morning it sold 45 items for €110. Write the system ( muffins, cookies) and find the solution.
Answer
, ; muffins and cookies.
Solution
Exercise 3: How many solutions?
Without solving, decide how many solutions each system has: (a) and , (b) and , (c) and .
Answer
(a) infinitely many, (b) none, (c) exactly one.
Solution
(a) The second equation is the first multiplied by 2: the same line, so infinitely many solutions. (b) The left side is again twice the first, but : parallel lines, no solution. (c) The left sides are not multiples of each other, so the lines cross once. (The solution is : , .)
Exercise 4: Brute force with a budget
A teacher spends exactly €100 on pens at €4 and notebooks at €6, buying 20 items in total. Write a short program that tries every possible number of pens and prints the solution.
Answer
10 pens and 10 notebooks.
Solution
The system is and . Loop over and let the first equation decide :
for p in range(21):
n = 20 - p
if 4 * p + 6 * n == 100:
print("pens:", p, "notebooks:", n)pens: 10 notebooks: 10
Check: ✓.
Test yourself
What is a solution of a system of two equations in and ?
- Any pair that satisfies at least one equation
- A pair that satisfies both equations at the same time
- The value of only
- The sum of the two equations
Solving a system leads to the statement . What does that mean?
- There are infinitely many solutions
- The system has no solution: the lines are parallel
- You made an arithmetic error, always
How many solutions can a system of two linear equations in two unknowns NOT have?
- Exactly two
- Exactly one
- None
- Infinitely many