TExcelTAD
Home › Basic Math & Pre-Algebra › Solving Equations

Solving Equations

An equation says that two expressions are equal. Solving it means finding the value of the variable that makes the statement true. The method is like keeping a balance level: whatever you do to one side, you also do to the other. This lesson covers one-step and two-step equations and equations with the variable on both sides. It finishes by checking the work with SymPy.

The balance idea

Think of 2x+3=112x + 3 = 11 as a balance scale with 2x+32x + 3 on the left pan and 1111 on the right. The pans are level. To find xx we strip things off the left side until only xx remains, and we keep the scale level by doing exactly the same to the right side.

Every step uses an inverse operation, the operation that undoes another one:

To undo Do this to both sides
+3+3 subtract 3
−7-7 add 7
×4\times 4 divide by 4
÷5\div 5 multiply by 5

Undo things in the reverse order of operations: first the additions and subtractions, then the multiplications and divisions.

2x+3=112x=8subtract 3 from both sidesx=4divide both sides by 2check: 2⋅4+3=11 ✓\begin{aligned} 2x + 3 &= 11 \\ 2x &= 8 && \text{subtract 3 from both sides} \\ x &= 4 && \text{divide both sides by 2} \\ \text{check: } 2 \cdot 4 + 3 &= 11\ \checkmark \end{aligned}

Tip: Always check by substituting the answer into the original equation. That one line catches most sign mistakes.

Variables on both sides

If xx appears on both sides, first gather the xx terms on one side and the numbers on the other:

5x−4=2x+113x−4=11subtract 2x from both sides3x=15add 4x=5divide by 3check: 5⋅5−4=21 and 2⋅5+11=21 ✓\begin{aligned} 5x - 4 &= 2x + 11 \\ 3x - 4 &= 11 && \text{subtract } 2x \text{ from both sides} \\ 3x &= 15 && \text{add 4} \\ x &= 5 && \text{divide by 3} \\ \text{check: } 5 \cdot 5 - 4 &= 21 \text{ and } 2 \cdot 5 + 11 = 21\ \checkmark \end{aligned}

With brackets, distribute first. With fractions, multiply both sides by the LCM of the denominators so the fractions disappear:

x3+x4=74x+3x=84multiply both sides by 127x=84x=12\begin{aligned} \frac{x}{3} + \frac{x}{4} &= 7 \\ 4x + 3x &= 84 && \text{multiply both sides by 12} \\ 7x &= 84 \\ x &= 12 \end{aligned}

Python's fractions module keeps every step exact, so you can follow the balance method without any rounding:

python · try it yourself
from fractions import Fraction as F

# solve a*x + b = c*x + d step by step
a, b, c, d = F(5), F(-4), F(2), F(11)
print(f"{a}x + ({b}) = {c}x + {d}")
a, c = a - c, 0
print(f"{a}x + ({b}) = {d}      subtract {F(2)}x")
d, b = d - b, 0
print(f"{a}x = {d}      add 4")
x = d / a
print(f"x = {x}")

# a fraction answer stays exact
print("3x + 1 = 8  ->  x =", (F(8) - 1) / 3)
5x + (-4) = 2x + 11
3x + (-4) = 11      subtract 2x
3x = 15      add 4
x = 5
3x + 1 = 8  ->  x = 7/3

When there is no solution or every number works

Sometimes the variable cancels completely:

  • 2x+1=2x+52x + 1 = 2x + 5 becomes 1=51 = 5, which is false. There is no solution.
  • 3(x+2)=3x+63(x + 2) = 3x + 6 becomes 6=66 = 6, which is always true. Every number is a solution (an identity).

Checking with SymPy

SymPy solves equations symbolically. Eq(left, right) builds an equation and solve returns a list of solutions. An empty list means no solution. Solve by hand first, then use SymPy as a check:

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

x = symbols("x")
print(solve(Eq(5*x - 4, 2*x + 11), x))
print(solve(Eq(x/3 + x/4, 7), x))
print(solve(Eq(3*x + 1, 8), x))
print(solve(Eq(2*x + 1, 2*x + 5), x))
print(solve(Eq(Rational(3, 4)*x - 2, Rational(1, 2)), x))
[5]
[12]
[7/3]
[]
[10/3]

In software

Programmers rearrange equations all the time, usually to solve a formula for a different variable:

  • Inverse lerp. Linear interpolation is v=a+t(b−a)v = a + t(b - a). Solving for tt gives t=v−ab−at = \frac{v - a}{b - a}, which tells you how far along a progress bar, a slider or an animation a value is (see Lerp).
  • Unit and temperature conversion. F=1.8C+32F = 1.8C + 32 turned around gives C=F−321.8C = \frac{F - 32}{1.8}.
  • Time to reach a target. If health regenerates by 4 per second from 30, solving 30+4t=10030 + 4t = 100 gives t=17.5 st = 17.5\ \text{s}.
python · try it yourself
def inverse_lerp(a, b, v):
    return (v - a) / (b - a)

print(inverse_lerp(0, 200, 50))     # 50 px along a 200 px bar
print(inverse_lerp(-10, 30, 20))    # 20 °C on a −10..30 scale
print((100 - 30) / 4, "seconds")    # 30 + 4t = 100
0.25
0.75
17.5 seconds

Exercises

Exercise 1: Two steps

Solve 7x−9=407x - 9 = 40.

Answer

x=7x = 7

Solution
7x−9=407x=49add 9x=7divide by 7check: 7⋅7−9=40 ✓\begin{aligned} 7x - 9 &= 40 \\ 7x &= 49 && \text{add 9} \\ x &= 7 && \text{divide by 7} \\ \text{check: } 7 \cdot 7 - 9 &= 40\ \checkmark \end{aligned}

Exercise 2: Brackets on both sides

Solve 4(x−3)=2(x+5)4(x - 3) = 2(x + 5).

Answer

x=11x = 11

Solution
4x−12=2x+10distribute2x−12=10subtract 2x2x=22add 12x=11check: 4⋅8=32 and 2⋅16=32 ✓\begin{aligned} 4x - 12 &= 2x + 10 && \text{distribute} \\ 2x - 12 &= 10 && \text{subtract } 2x \\ 2x &= 22 && \text{add 12} \\ x &= 11 \\ \text{check: } 4 \cdot 8 &= 32 \text{ and } 2 \cdot 16 = 32\ \checkmark \end{aligned}

Exercise 3: Clear the fractions

Solve x2−1=x5+2\frac{x}{2} - 1 = \frac{x}{5} + 2.

Answer

x=10x = 10

Solution

The LCM of 2 and 5 is 10, so multiply every term by 10:

5x−10=2x+203x=30x=10check: 102−1=4 and 105+2=4 ✓\begin{aligned} 5x - 10 &= 2x + 20 \\ 3x &= 30 \\ x &= 10 \\ \text{check: } \tfrac{10}{2} - 1 &= 4 \text{ and } \tfrac{10}{5} + 2 = 4\ \checkmark \end{aligned}
python · try it yourself
from sympy import symbols, Eq, solve
x = symbols("x")
print(solve(Eq(x/2 - 1, x/5 + 2), x))
[10]

Exercise 4: Solve a formula

A phone plan costs €12 per month plus €0.05 per MB of data. Write the cost equation for a bill of €20 and find how many MB were used. Then write a Python function mb_used(bill) that solves it for any bill.

Answer

12+0.05m=2012 + 0.05m = 20, so m=160 MBm = 160\ \text{MB}.

Solution
12+0.05m=200.05m=8subtract 12m=160divide by 0.05\begin{aligned} 12 + 0.05m &= 20 \\ 0.05m &= 8 && \text{subtract 12} \\ m &= 160 && \text{divide by 0.05} \end{aligned}

Solving 12+0.05m=bill12 + 0.05m = \text{bill} for mm in general gives m=bill−120.05m = \frac{\text{bill} - 12}{0.05}:

python · try it yourself
def mb_used(bill):
    return (bill - 12) / 0.05

print(round(mb_used(20), 2), round(mb_used(31.5), 2))
160.0 390.0

Test yourself

What is the first step to solve 3x+8=293x + 8 = 29 by the balance method?

  1. Divide both sides by 3
  2. Subtract 8 from both sides
  3. Add 8 to both sides
  4. Multiply both sides by 3

How many solutions does 4x−2=4x+34x - 2 = 4x + 3 have?

  1. One
  2. Two
  3. None
  4. Infinitely many

Solving v=a+t(b−a)v = a + t(b - a) for tt gives:

  1. t=v(b−a)−at = v(b - a) - a
  2. t=v−ab−at = \frac{v - a}{b - a}
  3. t=b−av−at = \frac{b - a}{v - a}
  4. t=v−a−bt = v - a - b