TExcelTAD
Home › Algebra › Systems of Equations

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 aa and the number of child tickets cc. The story gives two facts, so you get two equations:

{a+c=20(number of tickets)12a+7c=195(money in euros)\begin{cases} a + c = 20 & \text{(number of tickets)} \\ 12a + 7c = 195 & \text{(money in euros)} \end{cases}

Each equation alone allows many pairs. a+c=20a + c = 20 is true for (0,20)(0, 20), (1,19)(1, 19), (5,15)(5, 15) 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:

python · try it yourself
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: 11+9=2011 + 9 = 20 and 12⋅11+7⋅9=132+63=19512 \cdot 11 + 7 \cdot 9 = 132 + 63 = 195. 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?
x+y=5x + y = 5, x−y=1x - y = 1 (3,2)(3, 2) 3+2=53 + 2 = 5 ✓ 3−2=13 - 2 = 1 ✓ yes
x+y=5x + y = 5, x−y=1x - y = 1 (4,1)(4, 1) 4+1=54 + 1 = 5 ✓ 4−1=34 - 1 = 3 ✗ no
2x+y=72x + y = 7, x−3y=0x - 3y = 0 (3,1)(3, 1) 6+1=76 + 1 = 7 ✓ 3−3=03 - 3 = 0 ✓ 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 x+y=5x + y = 5, x−y=1x - y = 1 a single pair (3,2)(3, 2)
parallel, different none (inconsistent) x+y=5x + y = 5, x+y=8x + y = 8 a false statement such as 0=30 = 3
the same line infinitely many (dependent) x+y=5x + y = 5, 2x+2y=102x + 2y = 10 a true statement such as 0=00 = 0

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:

python · try it yourself
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 yy works, as long as x=5−yx = 5 - y": 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 2×22 \times 2 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 (2,3)(2, 3), (4,−1)(4, -1) and (1,5)(1, 5) solve the system x+y=3x + y = 3, 2x+y=72x + y = 7?

Answer

Only (4,−1)(4, -1).

Solution
(2,3):2+3=5≠3×(4,−1):4+(−1)=3 ✓2⋅4+(−1)=7 ✓solution(1,5):1+5=6≠3×\begin{aligned} (2, 3)&: & 2 + 3 &= 5 \ne 3 & & \times \\ (4, -1)&: & 4 + (-1) &= 3\ \checkmark \quad 2 \cdot 4 + (-1) = 7\ \checkmark & & \text{solution} \\ (1, 5)&: & 1 + 5 &= 6 \ne 3 & & \times \end{aligned}

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 (mm muffins, kk cookies) and find the solution.

Answer

m+k=45m + k = 45, 3m+2k=1103m + 2k = 110; m=20m = 20 muffins and k=25k = 25 cookies.

Solution
m+k=45→k=45−m3m+2k=110→3m+2(45−m)=110→3m+90−2m=110→m=20, k=25check: 20+25=45 ✓3⋅20+2⋅25=60+50=110 ✓\begin{aligned} m + k = 45 &\quad\to\quad k = 45 - m \\ 3m + 2k = 110 &\quad\to\quad 3m + 2(45 - m) = 110 \\ &\phantom{\quad\to\quad} 3m + 90 - 2m = 110 \\ &\phantom{\quad\to\quad} m = 20,\ k = 25 \\[1ex] \text{check: } &20 + 25 = 45\ \checkmark \quad 3 \cdot 20 + 2 \cdot 25 = 60 + 50 = 110\ \checkmark \end{aligned}

Exercise 3: How many solutions?

Without solving, decide how many solutions each system has: (a) 3x−y=43x - y = 4 and 6x−2y=86x - 2y = 8, (b) 3x−y=43x - y = 4 and 6x−2y=56x - 2y = 5, (c) 3x−y=43x - y = 4 and x+y=4x + y = 4.

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 2⋅4=8≠52 \cdot 4 = 8 \ne 5: parallel lines, no solution. (c) The left sides are not multiples of each other, so the lines cross once. (The solution is (2,2)(2, 2): 6−2=46 - 2 = 4, 2+2=42 + 2 = 4.)

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 p+n=20p + n = 20 and 4p+6n=1004p + 6n = 100. Loop over pp and let the first equation decide nn:

python · try it yourself
for p in range(21):
    n = 20 - p
    if 4 * p + 6 * n == 100:
        print("pens:", p, "notebooks:", n)
pens: 10 notebooks: 10

Check: 4⋅10+6⋅10=40+60=1004 \cdot 10 + 6 \cdot 10 = 40 + 60 = 100 ✓.

Test yourself

What is a solution of a system of two equations in xx and yy?

  1. Any pair that satisfies at least one equation
  2. A pair that satisfies both equations at the same time
  3. The value of xx only
  4. The sum of the two equations

Solving a system leads to the statement 0=70 = 7. What does that mean?

  1. x=7x = 7
  2. There are infinitely many solutions
  3. The system has no solution: the lines are parallel
  4. You made an arithmetic error, always

How many solutions can a system of two linear equations in two unknowns NOT have?

  1. Exactly two
  2. Exactly one
  3. None
  4. Infinitely many