TExcelTAD
Home › Algebra › The Substitution Method

The Substitution Method

The substitution method solves one equation for one unknown and plugs that expression into the other equation. The second equation then has a single unknown left. Substitution is the natural choice when a variable is already isolated, and it also works for systems that are not linear, such as a line meeting a parabola.

The idea

Solve y=2x−1y = 2x - 1 and 3x+4y=183x + 4y = 18.

The first equation already says what yy is, so replace yy in the second equation by 2x−12x - 1:

3x+4(2x−1)=183x+8x−4=1811x=22→ x=2y=2⋅2−1=3check: 3⋅2+4⋅3=6+12=18 ✓\begin{aligned} 3x + 4(2x - 1) &= 18 \\ 3x + 8x - 4 &= 18 \\ 11x &= 22 && \to\ x = 2 \\ y &= 2 \cdot 2 - 1 = 3 \\ &\text{check: } 3 \cdot 2 + 4 \cdot 3 = 6 + 12 = 18\ \checkmark \end{aligned}

The solution is (2,3)(2, 3). The parentheses in the first line matter: you replace the whole yy by the whole expression.

The recipe

  1. Pick an equation and solve it for one variable, preferably one with coefficient 1 or −1 (no fractions appear).
  2. Substitute that expression into the other equation.
  3. Solve the resulting one-variable equation.
  4. Put the value back into the expression from step 1 to get the second variable.
  5. Check both original equations.

Example: 5x−2y=45x - 2y = 4 and x+3y=11x + 3y = 11. The xx in the second equation has coefficient 1:

x=11−3y5(11−3y)−2y=455−15y−2y=4−17y=−51→ y=3x=11−9=2check: 5⋅2−2⋅3=4 ✓2+3⋅3=11 ✓\begin{aligned} x &= 11 - 3y \\ 5(11 - 3y) - 2y &= 4 \\ 55 - 15y - 2y &= 4 \\ -17y &= -51 && \to\ y = 3 \\ x &= 11 - 9 = 2 \\ &\text{check: } 5 \cdot 2 - 2 \cdot 3 = 4\ \checkmark \quad 2 + 3 \cdot 3 = 11\ \checkmark \end{aligned}
Situation Better method
a variable is already isolated (y=…y = \ldots) or has coefficient ±1\pm 1 substitution
matching or opposite coefficients, or all coefficients large elimination
one equation is not linear (x2x^2, xyxy, x\sqrt{x} …) substitution

Both methods always give the same answer; the choice is only about how much arithmetic you do.

Substitution with SymPy

SymPy can carry out each step exactly as you would, which makes it a good way to check your work:

python · try it yourself
from sympy import symbols, Eq, solve

x, y = symbols("x y")
eq1 = Eq(5*x - 2*y, 4)
eq2 = Eq(x + 3*y, 11)

x_expr = solve(eq2, x)[0]          # step 1: x in terms of y
print("x =", x_expr)
step2 = eq1.subs(x, x_expr)        # step 2: substitute into eq1
print("substituted:", step2)
y_val = solve(step2, y)[0]         # step 3
x_val = x_expr.subs(y, y_val)      # step 4
print("solution:", x_val, y_val)
x = 11 - 3*y
substituted: Eq(55 - 17*y, 4)
solution: 2 3

SymPy prints * for multiplication and has already simplified 5(11−3y)−2y5(11 - 3y) - 2y to 55−17y55 - 17y.

When the system is not linear

Elimination needs matching terms, so it rarely helps when one equation is curved. Substitution still works. Where does the line y=x+2y = x + 2 meet the parabola y=x2y = x^2?

x2=x+2x2−x−2=0(x−2)(x+1)=0→ x=2 or x=−1y=x+2:(2,4) and (−1,1)\begin{aligned} x^2 &= x + 2 \\ x^2 - x - 2 &= 0 \\ (x - 2)(x + 1) &= 0 && \to\ x = 2 \text{ or } x = -1 \\ y = x + 2&: \quad (2, 4) \text{ and } (-1, 1) \end{aligned}

Two solutions, which a linear system can never have. The quadratic step uses factoring; in general you may need the quadratic formula.

python · try it yourself
from sympy import symbols, solve

x, y = symbols("x y")
print(solve([y - x**2, y - (x + 2)], [x, y]))
[(-1, 1), (2, 4)]

In software: mixing problems

A chemistry lab (or a paint mixer, or a coffee roaster) combines two stocks to hit a target. Mixing problems always give one equation for the amount and one for the ingredient.

How many litres of a 20 % solution and a 50 % solution make 12 litres of a 30 % solution?

x+y=12(litres)0.2x+0.5y=0.3⋅12(litres of the dissolved substance=3.6)substitute y=12−x:0.2x+0.5(12−x)=3.60.2x+6−0.5x=3.6−0.3x=−2.4→ x=8, y=4\begin{aligned} x + y &= 12 && \text{(litres)} \\ 0.2x + 0.5y &= 0.3 \cdot 12 && \text{(litres of the dissolved substance} = 3.6\text{)} \\ &\text{substitute } y = 12 - x\text{:} \\ 0.2x + 0.5(12 - x) &= 3.6 \\ 0.2x + 6 - 0.5x &= 3.6 \\ -0.3x &= -2.4 && \to\ x = 8,\ y = 4 \end{aligned}

Exactly the same system appears when you build a machine-learning data set from two sources: source A has 20 % positive labels, source B has 50 %, and you want 12 000 rows with 30 % positives. Take 8 000 rows from A and 4 000 from B. A short function solves every case:

python · try it yourself
from fractions import Fraction as F

def mix(p1, p2, target, total):
    """Amounts of stock 1 and 2 (concentrations p1, p2) giving `total` at `target`."""
    # x + y = total,  p1·x + p2·y = target·total;  y = total − x
    x = (target * total - p2 * total) / (p1 - p2)
    return x, total - x

print(*mix(F(20, 100), F(50, 100), F(30, 100), 12))
print(*mix(F(20, 100), F(50, 100), F(30, 100), 12000))
print(*mix(F(20, 100), F(50, 100), F(60, 100), 12))   # impossible target
8 4
8000 4000
-4 16

The formula comes straight from the substitution: p1x+p2(T−x)=tTp_1 x + p_2(T - x) = tT gives x=T(t−p2)p1−p2x = \frac{T(t - p_2)}{p_1 - p_2}. If the target lies outside the range of the two stocks (say 60 % from 20 % and 50 %), one amount comes out negative: no real mixture exists.

Exercises

Exercise 1: Already isolated

Solve x=3yx = 3y and 2x+y=212x + y = 21.

Answer

x=9x = 9, y=3y = 3.

Solution
2(3y)+y=21→7y=21→y=3x=3⋅3=9check: 2⋅9+3=21 ✓\begin{aligned} &2(3y) + y = 21 \to 7y = 21 \to y = 3 \\ &x = 3 \cdot 3 = 9 \\ &\text{check: } 2 \cdot 9 + 3 = 21\ \checkmark \end{aligned}

Exercise 2: Isolate first

Solve 4x−3y=14x - 3y = 1 and x−y=−1x - y = -1.

Answer

x=4x = 4, y=5y = 5.

Solution
second equation: x=y−14(y−1)−3y=1→4y−4−3y=1→y=5x=5−1=4check: 16−15=1 ✓4−5=−1 ✓\begin{aligned} &\text{second equation: } x = y - 1 \\ &4(y - 1) - 3y = 1 \to 4y - 4 - 3y = 1 \to y = 5 \\ &x = 5 - 1 = 4 \\ &\text{check: } 16 - 15 = 1\ \checkmark \quad 4 - 5 = -1\ \checkmark \end{aligned}

Exercise 3: A coffee blend

A roaster mixes beans costing €18 per kg with beans costing €30 per kg to make 40 kg of a blend worth €21 per kg. How many kg of each?

Answer

30 kg of the €18 beans and 10 kg of the €30 beans.

Solution
c+e=40→e=40−c18c+30e=21⋅40=84018c+30(40−c)=840→18c+1200−30c=840→−12c=−360→c=30e=10check: 18⋅30+30⋅10=540+300=840 ✓\begin{aligned} &c + e = 40 \to e = 40 - c \\ &18c + 30e = 21 \cdot 40 = 840 \\ &18c + 30(40 - c) = 840 \to 18c + 1200 - 30c = 840 \to -12c = -360 \to c = 30 \\ &e = 10 \\ &\text{check: } 18 \cdot 30 + 30 \cdot 10 = 540 + 300 = 840\ \checkmark \end{aligned}

Exercise 4: Line meets parabola

Find all intersection points of y=x2−3y = x^2 - 3 and y=2xy = 2x. Check them with SymPy.

Answer

(−1,−2)(-1, -2) and (3,6)(3, 6).

Solution
x2−3=2x→x2−2x−3=0→(x−3)(x+1)=0x=3 ⁣: y=6x=−1 ⁣: y=−2\begin{aligned} &x^2 - 3 = 2x \to x^2 - 2x - 3 = 0 \to (x - 3)(x + 1) = 0 \\ &x = 3\colon\ y = 6 \qquad x = -1\colon\ y = -2 \end{aligned}
python · try it yourself
from sympy import symbols, solve
x, y = symbols("x y")
print(solve([y - (x**2 - 3), y - 2*x], [x, y]))
[(-1, -2), (3, 6)]

Test yourself

In the system 3x+2y=123x + 2y = 12 and y=x−4y = x - 4, what equation do you get after substituting?

  1. 3x+2x−4=123x + 2x - 4 = 12
  2. 3x+2(x−4)=123x + 2(x - 4) = 12
  3. 3(x−4)+2y=123(x - 4) + 2y = 12
  4. 3x+2y=x−43x + 2y = x - 4

Which variable is the easiest to isolate in 2x+y=72x + y = 7, 5x−3y=15x - 3y = 1?

  1. xx in the second equation
  2. yy in the second equation
  3. yy in the first equation
  4. xx in the first equation

Why is substitution preferred for a line and a parabola?

  1. Elimination cannot cancel an x2x^2 term against a linear equation, but substitution turns the system into one quadratic
  2. Substitution is always faster
  3. Parabolas only have one point
  4. Elimination gives wrong answers for curves