Sub topic 5
Solving the Equation
This chapter assumes you can do arithmetic with integers, fractions, and decimals, and that you know the order of operations. It also assumes you know what a variable and an expression are. You should already be able to define a variable and write an equation from a word problem. Here the equation is given, and the job is to find the value of the variable.
What "solving" means
To solve a linear equation in one variable is to find the value that makes both sides equal. The method is to isolate the variable: rewrite the equation in steps until it reads x = number.
Each step must keep the equation true. An equation is a balance, so whatever you do to one side, you do to the other. Every step uses an inverse operation, which is an operation that undoes another:
| Operation in the equation | Inverse applied to both sides |
|---|---|
| Add 7 | Subtract 7 |
| Subtract 7 | Add 7 |
| Multiply by 3 | Divide by 3 |
| Divide by 3 | Multiply by 3 |
Because you undo operations, you work in the reverse of the order of operations. Addition and subtraction are removed first, then multiplication and division.
A standard procedure
Following the same order every time makes errors easier to find.
Not every equation needs every step. Skip the ones that do not apply, but keep the order.
Worked example: parentheses
In the ticket problem, 10 tickets cost $62 in total. Adult tickets cost $8 and child tickets cost $5. Let a be the number of adult tickets. The child tickets then number 10 - a, and the equation is:
8a + 5(10 - a) = 62- Expand:
8a + 50 - 5a = 62. The 5 multiplies both terms inside the parentheses, including the-a. - Combine like terms:
3a + 50 = 62. - Subtract 50 from both sides:
3a = 12. - Divide both sides by 3:
a = 4.
So there are 4 adult tickets and 6 child tickets. Check against the words: 8(4) + 5(6) = 32 + 30 = 62.
The same arithmetic in Python, using exact fractions so no rounding appears:
from fractions import Fraction
# 10 tickets total, adult $8, child $5, total $62. Let a = number of adults.
# 8a + 5(10 - a) = 62 -> 3a + 50 = 62
a = Fraction(62 - 50, 3)
print(a, 10 - a) # 4 6
print(8 * a + 5 * (10 - a) == 62) # TrueVariables on both sides
Many rate and comparison problems produce a variable on each side. Move the variable terms to one side by adding or subtracting a variable term from both sides. It is usually tidier to move them toward the larger coefficient, so the coefficient stays positive, but either direction gives the same answer.
Car A leaves at 60 mph. Car B leaves 1 hour later at 80 mph. Let t be the hours Car A has travelled when B catches up. Then B has travelled t - 1 hours, and the distances are equal:
60t = 80(t - 1)
60t = 80t - 80 expand
-20t = -80 subtract 80t from both sides
t = 4 divide by -20Both signs are negative, so the quotient is positive. Check: A has gone 60 × 4 = 240 miles, and B has gone 80 × 3 = 240 miles.
# Car A leaves at 60 mph. Car B leaves 1 hour later at 80 mph.
# Let t = hours Car A has travelled when B catches up.
# 60t = 80(t - 1) -> 20t = 80
t = 80 / 20
print(t) # 4.0
print(60 * t == 80 * (t - 1)) # TrueNegative signs and parentheses
A minus sign in front of parentheses applies to every term inside. This is the most common source of wrong answers at this stage. Solve 5 - 2(x - 3) = 3x - 4:
- Expand:
5 - 2x + 6 = 3x - 4. Note that-2 × -3 = +6. - Combine like terms on the left:
11 - 2x = 3x - 4. - Add
2xto both sides:11 = 5x - 4. - Add 4 to both sides:
15 = 5x. - Divide by 5:
x = 3.
Check: the left side is 5 - 2(3 - 3) = 5, and the right side is 3(3) - 4 = 5.
The solution can be written on either side of the equals sign. 15 = 5x and x = 3 mean the same as 5x = 15 and 3 = x.
Fractions and decimals
Fractions and decimals are easiest to remove at the start. Multiply every term on both sides by a number that clears all the denominators. Use the least common multiple of the denominators, or a power of 10 for decimals.
Solve x/3 + x/4 = 14. The least common multiple of 3 and 4 is 12:
12(x/3) + 12(x/4) = 12(14)
4x + 3x = 168
7x = 168
x = 24Check: 24/3 + 24/4 = 8 + 6 = 14.
For a decimal, such as a 20% discount, the equation 0.8p = 48 can be multiplied by 10 to give 8p = 480, so p = 60. You can also treat 0.8 as the fraction 4/5 and divide by it:
from fractions import Fraction
# A jacket costs $48 after a 20% discount. Let p = original price.
# 0.8p = 48 -> p = 48 / 0.8
p = Fraction(48) / Fraction(4, 5)
print(p) # 60
print(p * Fraction(4, 5) == 48) # TrueEquations with no solution or every solution
Sometimes the variable cancels completely. Then you are left with a statement about numbers only, and it is either true or false.
2(x + 3) = 2x + 5becomes2x + 6 = 2x + 5, then6 = 5. This is false for everyx, so there is no solution.2(x + 3) = 2x + 6becomes6 = 6. This is true for everyx, so there are infinitely many solutions.
In a word problem, the first case usually means the situation never happens. Two parallel trains never meet, and two equal-priced plans never become equal. The second case usually means you wrote the same relationship twice. If either appears, reread the problem and your equation before trusting anything.
A small solver you can reuse
Any equation of the form ax + b = cx + d reduces to (a - c)x = d - b. The code below uses that fact and handles the special cases from the previous section.
from fractions import Fraction
def solve_linear(a, b, c, d):
"""Solve a*x + b = c*x + d exactly. Returns a Fraction, 'none', or 'all'."""
a, b, c, d = (Fraction(v) for v in (a, b, c, d))
coefficient = a - c
constant = d - b
if coefficient == 0:
return "all" if constant == 0 else "none"
return constant / coefficient
print(solve_linear(3, 50, 0, 62)) # 4 from 3a + 50 = 62
print(solve_linear(60, 0, 80, -80)) # 4 from 60t = 80t - 80
print(solve_linear(2, 6, 2, 5)) # none from 2x + 6 = 2x + 5
print(solve_linear(2, 6, 2, 6)) # all from 2x + 6 = 2x + 6Expand parentheses and combine like terms by hand first, then pass the four numbers in. The function removes arithmetic mistakes in the last step, but it cannot tell you whether your equation matches the problem.
Common errors
| Error | Example | Fix |
|---|---|---|
| Distributing to only the first term | `5(10 - a)` written as `50 - a` | Multiply every term inside: `50 - 5a` |
| Dropping a negative | `-2(x - 3)` written as `-2x - 6` | `-2 × -3 = +6`, so `-2x + 6` |
| Changing only one side | Subtracting 50 from the left only | Apply every step to both sides |
| Wrong inverse | `3a = 12` gives `a = 12 - 3` | The inverse of multiplying is dividing |
| Not multiplying a constant when clearing fractions | `4x + 3x = 14` instead of `= 168` | Multiply every term by the common denominator |
| Sign error when dividing | `-20t = -80` gives `t = -4` | Negative divided by negative is positive |
Check against the words, not just the equation
Substituting into your own equation only proves you did the algebra correctly. If the equation itself is wrong, the check passes and the answer is still wrong. Always put the value back into the original wording and ask whether the facts hold. In the ticket problem, that means counting 4 adult and 6 child tickets and confirming the total is $62. The next chapter covers this in detail.
Exercise
Plumber A charges a $40 call-out fee plus $25 per hour. Plumber B charges a $10 call-out fee plus $35 per hour. Let h be the number of hours. After how many hours do the two plumbers cost the same, and what is that cost?
Show answer
The costs are equal when 40 + 25h = 10 + 35h. Subtract 25h from both sides: 40 = 10 + 10h. Subtract 10: 30 = 10h. Divide by 10: h = 3. At 3 hours, A costs 40 + 25(3) = $115 and B costs 10 + 35(3) = $115. The costs are equal at 3 hours, at $115 each.
Exercise
Solve 3(2x - 1) = 4x + 9 and check your answer in the original equation.
Show answer
Expand the left side: 6x - 3 = 4x + 9. Subtract 4x from both sides: 2x - 3 = 9. Add 3: 2x = 12. Divide by 2: x = 6. Check: the left side is 3(2 · 6 - 1) = 3(11) = 33, and the right side is 4(6) + 9 = 33.
Exercise
What does it mean when solving an equation leaves you with 7 = 7, and what does it mean when you reach 7 = 9?
Show answer
7 = 7 is always true, so every value of the variable is a solution (infinitely many solutions). 7 = 9 is never true, so the equation has no solution. In a word problem, either result is a signal to recheck whether the equation matches the situation.