Volume 1: Foundations to Precalculus · Part II: Algebra
Chapter 5. Linear Equations and Inequalities
A taxi charges a fixed fee plus a rate per mile. How far can you go for $25? When does one phone plan become cheaper than another? Where should an animation be 40% of the way through its move? Each is a linear question, and each is answered with the same small set of reversible moves. Linear equations are probably the most-used mathematics there is: every unit conversion, budget, dosage, "how long until?" and "how many will fit?" is one. This chapter turns those moves into an algorithm, then extends it from equations (one answer) to inequalities (a whole range of answers), absolute values (distances), and finally to the straight line itself, the picture behind all of it.
5.1. What makes an equation linear?
5.1.1. The problem
A taxi charges $3.00 to start the meter plus $2.50 per mile. Your ride cost $23.00. How far did you travel?
Call the distance \(d\) miles. Then the cost is \(3 + 2.5d\), and the information you have is
You can probably see the answer quickly: take off the $3 start fee to leave $20, and $20 at $2.50 a mile is 8 miles. That two-step mental calculation is exactly the algorithm this chapter formalises. Before we do that, let us name what kind of equation this is, because the name tells you which tools apply.
5.1.2. Vocabulary
|
Linear equation
A linear equation in one unknown \(x\) is an equation that can be rearranged into the form
\[ax + b = 0, \qquad a \neq 0,\]
where \(a\) and \(b\) are constants. The unknown appears only to the first power: no \(x^2\), no \(\sqrt{x}\), no \(1/x\), no \(x\) multiplied by another unknown. The name comes from the Latin linea, "line": graph \(y = ax + b\) and you get a straight line (Section 5.10). |
|
Solution, root, solution set
A solution of an equation is a value of the unknown that makes the equation a true statement. For equations of the form \(f(x) = 0\), a solution is also called a root. The solution set is the collection of all solutions. For a linear equation it contains exactly one number, no numbers, or every number (Section 5.4). For an inequality it is usually a whole interval. |
|
Equivalent equations
Two equations are equivalent if they have exactly the same solution set. \(2x + 1 = 7\), \(2x = 6\) and \(x = 3\) are equivalent. Solving an equation means producing a chain of equivalent equations that ends in something so simple, like \(x = 3\), that the solution set can be read off. |
Which of these are linear in \(x\)?
-
\(5x - 7 = 2x + 8\) — yes. Collect terms and it becomes \(3x - 15 = 0\).
-
\(\tfrac{1}{2}(x + 4) = \sqrt{2}\,x\) — yes. The coefficient \(\sqrt 2\) is irrational, but it is still a constant multiplying the first power of \(x\).
-
\(x^2 = 9\) — no, the unknown is squared (that is a quadratic; see Chapter 8).
-
\(\tfrac{3}{x} = 6\) — not as written, because \(x\) is in a denominator. Multiplying by \(x\) turns it into \(3 = 6x\), which is linear, but only after you have noted that \(x \neq 0\). We will come back to this subtlety.
-
\(xy = 6\) — no; it is a product of two unknowns.
5.2. Solving linear equations in one unknown
5.2.1. The problem
"I think of a number, multiply it by 3, subtract 5, and get 16. What was my number?"
Written as an equation, \(3x - 5 = 16\). The puzzle describes a little pipeline of operations applied to the unknown:
To recover \(x\) you run the pipeline backwards, undoing each stage with its inverse, last stage first:
The number was 7. Check: \(3 \cdot 7 - 5 = 16\). That is the entire idea of solving a linear equation. Everything else is bookkeeping for when the pipeline is messier: when \(x\) appears on both sides, inside brackets, or inside fractions.
5.2.2. Intuition: undo in reverse order
You put on socks, then shoes. To undo, you take off shoes first, then socks. Inverse operations undo in reverse order for the same reason: the last thing done to \(x\) is the outermost layer, so it has to come off first. In \(3x - 5\), the subtraction of 5 happened after the multiplication by 3 (order of operations), so it is undone first.
|
Inverse operation
An inverse operation undoes another. Adding \(k\) and subtracting \(k\) are inverses; multiplying by \(k\) and dividing by \(k\) are inverses, provided \(k \neq 0\). Applying an operation and then its inverse returns you to where you started. |
The second intuition is the balance from Chapter 4: an equation is a pair of scales in equilibrium. Whatever you do to one pan, you must do to the other, or the balance tips and the statement is no longer the one you started with.
5.2.3. Why it works
Why is it legitimate to "do the same thing to both sides"? Suppose \(x = s\) is a solution of \(L = R\), meaning that when \(x\) is replaced by \(s\) the two sides are the same number. Adding 5 to two equal numbers gives two equal numbers; multiplying two equal numbers by 3 gives two equal numbers. So every solution of the old equation is a solution of the new one.
That is only half of what we need. We also need the reverse: the new equation should not have gained solutions. That is where the inverse matters. If you added 5, you can subtract 5 to get back exactly the original equation, so any solution of the new equation is also a solution of the old one. Each step is reversible, and reversible steps produce equivalent equations.
Now you can see why multiplying both sides by zero is forbidden. Multiplying \(2x = 6\) by 0 gives \(0 = 0\), which is true for every \(x\). Information has been destroyed and cannot be recovered, because there is no "divide by 0" to undo it. The two legal moves, stated precisely:
The double arrow \(\Longleftrightarrow\) means "if and only if": each equation implies the other, so their solution sets are identical. Subtraction is adding \(-k\); division is multiplying by \(1/k\). Simplifying a side (expanding brackets, collecting like terms, as in Chapter 4) is the third legal move, since it does not change the value of that side at all.
5.2.4. The method
Input: an equation in which the unknown \(x\) appears only to the first power.
Steps:
-
Clear fractions: if any term has a numeric denominator, multiply every term on both sides by the lowest common denominator (Section 5.3).
-
Expand: remove brackets with the distributive law, watching signs.
-
Simplify each side: collect like terms separately on the left and on the right.
-
Collect: add or subtract so that all \(x\)-terms are on one side and all constant terms on the other. (Moving the \(x\)-terms toward the side with the larger \(x\)-coefficient keeps the coefficient positive.)
-
Isolate: you now have \(ax = c\). If \(a \neq 0\), divide both sides by \(a\): \(x = c/a\). If \(a = 0\), go to Section 5.4: there is no solution or every number is a solution.
-
Check: substitute the answer into the original equation and evaluate each side separately.
Output: the solution set: one number, the empty set, or all real numbers.
5.2.5. Worked examples
Example 1. Solve \(3(2x - 5) = 4x + 7\).
Check: left side \(3(2 \cdot 11 - 5) = 3 \cdot 17 = 51\); right side \(4 \cdot 11 + 7 = 51\). Equal, so \(x = 11\).
Example 2. Solve \(5 - 2(x - 3) = 3x - 4\).
The danger here is the minus sign in front of the bracket. \(-2(x - 3)\) means \(-2\) multiplied by each term inside: \((-2)(x) + (-2)(-3) = -2x + 6\).
Check: left \(5 - 2(3 - 3) = 5 - 0 = 5\); right \(3 \cdot 3 - 4 = 5\). Equal.
Notice the choice made at the fourth line. Adding \(2x\) to both sides moved the \(x\)-terms to the right, where they ended up with the positive coefficient \(5\). Subtracting \(3x\) instead would have given \(11 - 5x = -4\), then \(-5x = -15\), then \(x = 3\): the same answer, but with two extra negative signs to get wrong. An equation with \(x\) on the right, like \(3 = x\), is perfectly fine; equality is symmetric.
5.2.6. Alternative approaches
-
Reverse flowchart. For an equation where \(x\) appears exactly once, such as \(\frac{4x + 1}{3} - 2 = 5\), write the pipeline (\(\times 4\), \(+1\), \(\div 3\), \(-2\)) and run it backwards from 5: \(5 + 2 = 7\), \(7 \times 3 = 21\), \(21 - 1 = 20\), \(20 \div 4 = 5\). So \(x = 5\). Fast and transparent, but useless once \(x\) appears more than once.
-
Guess and check (trial and improvement). Try values, see whether the left side is too big or too small, adjust. Fine for building intuition, slow and imprecise otherwise. It is, however, exactly what numerical methods do for equations that cannot be solved algebraically (Chapter 32).
-
Graphing. Plot \(y = 3(2x - 5)\) and \(y = 4x + 7\) and read off where they cross. This gives understanding and a sanity check, but only approximate answers by eye. We return to this view in Section 5.10.
-
Rearrange to \(ax + b = 0\) and use \(x = -b/a\). This is what a computer does (see the code below). By hand it is no faster than the procedure.
5.2.7. Choosing a method
For one-off equations by hand, use the procedure: it never fails and every step is checkable. Use the reverse flowchart when \(x\) appears once; it is quicker and harder to get wrong. Use a graph when you want to see the solution or to check a suspicious answer. Use guess-and-check only when the equation is not linear and no algebraic method is available.
|
Distributing a minus sign, and other classic slips
|
5.2.8. Where you’d use this
Any time a formula gives you the answer to the wrong question, you solve a linear equation to turn it round.
-
Shopping. A receipt says you paid $54.00 including 8% sales tax. The pre-tax price \(p\) satisfies \(1.08p = 54\), so \(p = 54 / 1.08 = 50\). (Subtracting 8% of $54 instead gives $49.68, a classic slip: the 8% was of the price, not of the total.)
-
Chemistry and medicine. Diluting a stock solution keeps the amount of solute fixed: \(C_1 V_1 = C_2 V_2\). To make 500 mL of 0.1 M solution from 2 M stock, solve \(2V_1 = 0.1 \times 500\): \(V_1 = 25\) mL of stock, topped up to 500 mL. Nurses do the same calculation for drug dilutions.
-
Mechanics. The constant-acceleration equation \(v = u + at\) is linear in each letter. A car accelerating from rest at \(3\ \text{m/s}^2\) reaches \(27\ \text{m/s}\) (about 60 mph) when \(27 = 0 + 3t\), i.e. after \(t = 9\) s.
-
Computing. A drawing program maps a world coordinate \(x\) to a screen pixel by \(p = 40 + 8x\) (a 40-pixel margin, 8 pixels per unit). When the user clicks pixel 360, the program solves \(40 + 8x = 360\) to find that they clicked world coordinate \(x = 40\). Every zoomable map, chart and game camera inverts a linear map like this on every mouse event.
|
Restoring and balancing
The word algebra comes from the title of al-Khwārizmī’s ninth-century book al-Kitāb al-mukhtaṣar fī ḥisāb al-jabr wa-l-muqābala. Al-jabr ("restoration") was the move of adding a term to both sides to cancel a subtracted quantity; al-muqābala ("balancing") was cancelling like terms on opposite sides. Those are precisely steps 4 and 3 of our procedure. Al-Khwārizmī’s own name, Latinised, gave us the word algorithm. Solving linear equations is where both words were born. |
|
Balance-scale solver
Show an equation as a balance scale with \(x\)-boxes and unit weights on each pan. The learner chooses an operation ("add 3 to both", "divide both by 2"); the scale applies it to both pans and the symbolic equation updates beside it. Illegal moves, such as acting on one pan only or dividing by zero, visibly tip the scale. A counter compares the learner’s number of steps with the minimum. |
5.3. Equations with fractions and decimals
5.3.1. The problem
Problems about shares and proportions ("a third of one amount, less a quarter of another") arrive full of fractions. A typical result is
You could work with the fractions throughout, but there is a better move. Every term can be multiplied by the same nonzero number without changing the solution set, so multiply by a number that cancels every denominator at once.
|
Lowest common denominator (LCD)
The lowest common denominator of several fractions is the least common multiple of their denominators: the smallest positive number each denominator divides into. For \(\tfrac{1}{3}\) and \(\tfrac{1}{4}\) it is \(12\); for \(\tfrac{1}{4}\) and \(\tfrac{1}{6}\) it is \(12\), not \(24\). (See Chapter 2.) Multiplying an equation through by the LCD is called clearing fractions. |
5.3.2. Worked example
Solve \(\dfrac{x + 1}{3} - \dfrac{x - 2}{4} = 1\). The LCD of 3 and 4 is 12.
Check: \(\frac{2 + 1}{3} - \frac{2 - 2}{4} = 1 - 0 = 1\). Correct.
The single most common error here is in line 2. The fraction bar is a grouping symbol: \(\frac{x - 2}{4}\) means \(\frac{1}{4}(x - 2)\), so after clearing, the \(-3\) multiplies the whole of \((x - 2)\). Writing the brackets explicitly at this stage, before expanding, prevents the mistake.
Decimals are fractions in disguise, cleared by a power of 10. For \(0.05x + 0.12(200 - x) = 17\), multiply through by 100:
Check: \(0.05(100) + 0.12(100) = 5 + 12 = 17\).
5.3.3. When the unknown is in a denominator
Strictly, \(\frac{2}{x} + 3 = \frac{5}{x}\) is not linear, but it becomes linear after multiplying by \(x\). The catch is that \(x\) could be zero, and multiplying by zero is not reversible. So first record the restriction \(x \neq 0\), then proceed:
\(x = 1\) satisfies the restriction, and the check \(2 + 3 = 5\) confirms it.
|
Extraneous solutions
Multiplying by an expression that can be zero may introduce a false solution. Solve \(\dfrac{x}{x - 3} = \dfrac{3}{x - 3} + 2\). The restriction is \(x \neq 3\). Multiplying by \((x - 3)\):
\[x = 3 + 2(x - 3) = 2x - 3 \quad\Longrightarrow\quad x = 3.\]
But \(x = 3\) is forbidden: both fractions have zero denominators there. The original equation has no solution; the "3" is an extraneous solution created by the non-reversible step. This is why the check step in the procedure is not optional. Rational equations get full treatment alongside rational expressions in Chapter 7. |
5.4. One solution, none, or infinitely many
5.4.1. The problem
Try to solve \(3x + 1 = 3x + 4\). Subtract \(3x\) from both sides and you get \(1 = 4\). The \(x\) has vanished and left a false statement. What went wrong?
Nothing went wrong. The equation asks "which numbers \(x\) make \(3x + 1\) equal to \(3x + 4\)?" and the answer is "none": whatever \(x\) is, the right side is always 3 bigger. The algebra correctly reported that.
5.4.2. Why there are exactly three cases
After expanding and collecting, every linear-looking equation \(ax + b = cx + d\) becomes
Call the coefficient \(A = a - c\) and the right side \(B = d - b\). Then:
| Case | What happens | Solution set |
|---|---|---|
\(A \neq 0\) |
divide by \(A\) |
exactly one solution, \(x = B/A\) |
\(A = 0,\ B \neq 0\) |
\(0 = B\) is false for every \(x\) |
no solution (the empty set \(\varnothing\)) |
\(A = 0,\ B = 0\) |
\(0 = 0\) is true for every \(x\) |
every real number, \(\mathbb{R}\) |
|
Identity, contradiction, conditional equation
An identity is an equation true for every value of the variable, such as \(2(x + 3) = 2x + 6\). A contradiction is true for no value, such as \(x + 1 = x + 2\). A conditional equation is true for some values and false for others, such as \(2x = 6\). The symbol \(\varnothing\) denotes the empty set, the set with no elements; \(\mathbb{R}\) denotes the set of all real numbers. |
Example. Solve \(6x - 2(3x + 1) = -2\).
This is always true, so the solution set is \(\mathbb{R}\): every real number works. Test any value you like; \(x = 100\) gives \(600 - 602 = -2\).
The picture behind these cases is simple and will matter a great deal in Chapter 6. Graph each side as a line, \(y = ax + b\) and \(y = cx + d\). The \(x\)-coefficients \(a\) and \(c\) are the slopes. Different slopes: the lines cross exactly once. Equal slopes, different intercepts: parallel lines that never meet. Equal slopes and equal intercepts: the same line, meeting everywhere.
|
Reading 0 = 0 as x = 0
When the variable cancels and leaves \(0 = 0\), the answer is "all real numbers", not "\(x = 0\)". When it leaves something like \(0 = 3\), the answer is "no solution", not "\(x = 3\)". Write the solution set explicitly: \(\mathbb{R}\) or \(\varnothing\). |
5.5. Exercises: solving equations
-
Which of these are linear equations in \(x\)? (a) \(3x - 7 = 2\) (b) \(x^2 = 4\) (c) \(0.5(x + 2) = \sqrt{2}\,x\) (d) \(xy = 6\) (e) \(\frac{x}{4} = 9\).
-
Solve \(4x + 9 = 1\).
-
Solve \(7 - (2x - 5) = 3(x + 1) - 1\).
-
Solve \(\dfrac{2x - 1}{5} = \dfrac{x + 4}{3}\).
-
Solve \(\dfrac{x}{2} - \dfrac{x}{3} = 4\).
-
Classify each as identity or contradiction and give its solution set: (a) \(4(x - 1) = 4x - 4\) (b) \(2x + 3 = 2(x + 3)\).
-
For which value of \(k\) does \(kx + 2 = 3x - 1\) have no solution? Is there a value of \(k\) for which it has infinitely many?
-
A student writes: \(2(x + 3) = 10 \Rightarrow 2x + 3 = 10 \Rightarrow x = 3.5\). Find the error and give the correct solution.
Answers
-
(a), (c) and (e) are linear. (b) has \(x^2\); (d) is a product of two unknowns.
-
\(4x = 1 - 9 = -8\), so \(x = -2\). Check: \(-8 + 9 = 1\).
-
Expand: \(7 - 2x + 5 = 3x + 3 - 1\), so \(12 - 2x = 3x + 2\). Add \(2x\) and subtract 2: \(10 = 5x\), \(x = 2\). Check: left \(7 - (-1) = 8\), right \(3 \cdot 3 - 1 = 8\).
-
LCD 15: \(3(2x - 1) = 5(x + 4)\), so \(6x - 3 = 5x + 20\), \(x = 23\). Check: \(45/5 = 9\) and \(27/3 = 9\).
-
LCD 6: \(3x - 2x = 24\), so \(x = 24\). Check: \(12 - 8 = 4\).
-
(a) Expanding gives \(4x - 4 = 4x - 4\), then \(0 = 0\): identity, solution set \(\mathbb{R}\). (b) \(2x + 3 = 2x + 6\) gives \(3 = 6\): contradiction, solution set \(\varnothing\).
-
Collect: \((k - 3)x = -3\). If \(k = 3\) this reads \(0 = -3\): no solution. Infinitely many would need both \(k - 3 = 0\) and \(-3 = 0\), which is impossible, so no such \(k\). For every other \(k\) the unique solution is \(x = -3/(k - 3)\).
-
The 2 was not multiplied into the 3: \(2(x + 3) = 2x + 6\). Correctly, \(2x + 6 = 10\), \(2x = 4\), \(x = 2\). Check: \(2(5) = 10\).
5.6. Linear inequalities
5.6.1. The problem
Back in the taxi: you have $25. How far can you go? Now the question is not "which distance costs exactly $25" but "which distances cost at most $25":
The answer is not a single number but a whole range of numbers. Inequalities are how mathematics talks about budgets, limits, tolerances, capacities and thresholds: anything with "at most", "at least", "no more than", "exceeds".
|
Inequality symbols
\(<\) and \(>\) are strict inequalities; \(\le\) and \(\ge\) are non-strict (or weak). The narrow end of the symbol points at the smaller number. |
Solving the taxi inequality looks exactly like solving the equation:
Any distance up to 8.8 miles (and, since distance cannot be negative, at least 0) is affordable. So far, inequalities behave like equations. There is exactly one twist.
5.6.2. Intuition: why a negative multiplier flips the sign
Start with a true statement, \(2 < 4\), and multiply both sides by \(-1\). You get \(-2\) and \(-4\). Which is bigger? On the number line \(-2\) is to the right of \(-4\), so \(-2 > -4\). The inequality has reversed.
Geometrically, multiplying by \(-1\) is a mirror reflection of the number line about 0. A reflection turns left-to-right into right-to-left, so "is to the left of" becomes "is to the right of". Multiplying by any negative number is a reflection followed by a stretch, and the stretch does not change order, so every negative multiplier reverses the inequality.
5.6.3. Why it works
Here is the argument in symbols; it is short and it shows exactly where the sign of the multiplier enters. Recall that \(a < b\) means the same as \(b - a > 0\) (the gap from \(a\) up to \(b\) is positive).
Suppose \(a < b\), so \(b - a > 0\), and let \(k\) be any number. Then
-
If \(k > 0\): a positive times a positive is positive, so \(kb - ka > 0\), that is, \(ka < kb\). The order is kept.
-
If \(k < 0\): a negative times a positive is negative, so \(kb - ka < 0\), that is, \(ka > kb\). The order is reversed.
-
If \(k = 0\): both sides become 0 and all information is lost, just as with equations.
Adding the same number to both sides never changes the order, because \((b + k) - (a + k) = b - a\): the gap is unchanged. So the rules for inequalities are the rules for equations, plus one exception.
The same rules hold with \(\le\) in place of \(<\). Swapping the two sides also reverses the symbol: \(3 < x\) says the same thing as \(x > 3\).
5.6.4. The method
Input: an inequality, using \(<\), \(\le\), \(>\) or \(\ge\), in which \(x\) appears only to the first power.
Steps:
-
Clear fractions by multiplying by the (positive) LCD. Positive, so no flip.
-
Expand brackets and collect like terms on each side.
-
Add or subtract to put \(x\)-terms on one side and constants on the other.
-
Divide by the coefficient of \(x\). If that coefficient is negative, reverse the inequality symbol.
-
Write the solution set (as an inequality, in interval notation, and on a number line).
-
Check: pick one test value inside the solution set and one outside, and substitute both into the original inequality.
Output: the solution set, usually an interval.
5.6.5. Worked example
Solve \(7 - 3x \le 19\).
Check with a value inside, \(x = 0\): \(7 - 0 = 7 \le 19\) is true. A value outside, \(x = -5\): \(7 + 15 = 22 \le 19\) is false. The boundary, \(x = -4\): \(7 + 12 = 19 \le 19\) is true, so the endpoint belongs to the solution set, as \(\ge\) says. Solution set: \(\lbrack -4, \infty)\).
5.6.6. Alternative approach: avoid the flip altogether
You can sidestep the sign reversal by moving the \(x\)-term to whichever side makes its coefficient positive:
\(-4 \le x\) is the same statement as \(x \ge -4\). Many people find this method more reliable, because it replaces a rule you have to remember with a move you cannot get wrong. Use whichever you prefer; but know both, because when the coefficient is a symbol \(a\) whose sign you do not know, you need to split into cases \(a > 0\) and \(a < 0\) and the flip rule is unavoidable.
|
Inequality pitfalls
|
5.6.7. Interval notation and set notation
A solution like "all \(x\) with \(-2 \le x < 3\)" is common enough to deserve a compact notation.
|
Interval notation
An interval is an unbroken stretch of the number line. A square bracket means the endpoint is included; a round bracket (parenthesis) means it is excluded.
The symbol \(\infty\) (infinity) is not a number; \(\lbrack a, \infty)\) means "no upper limit". Infinity therefore always gets a round bracket. On a number line, a filled dot marks an included endpoint and an open circle an excluded one. |
|
Set-builder notation, membership, union and intersection
Set-builder notation \(\{x \mid x > 2\}\) is read "the set of all \(x\) such that \(x > 2\)". The vertical bar means "such that" (some books use a colon). \(x \in S\) means "\(x\) is an element of the set \(S\)"; for example \(3 \in (2, \infty)\). The union \(A \cup B\) is everything in \(A\) or \(B\) (or both); the intersection \(A \cap B\) is everything in both. These are developed properly in Chapter 21. |
5.6.8. Compound inequalities
A compound inequality joins two inequalities with "and" or "or".
"And": a double inequality. \(-3 < 2x + 1 \le 9\) means \(-3 < 2x + 1\) and \(2x + 1 \le 9\). Because the middle is sandwiched, you can apply each operation to all three parts at once:
Solution set \((-2, 4]\). Check the endpoints: \(x = -2\) gives \(-3 < -3\), false, so excluded; \(x = 4\) gives \(9 \le 9\), true, so included.
When the multiplier is negative, both symbols flip, and it is tidiest to rewrite the result so the smaller number is on the left:
"Or": a union. Solve \(3x - 1 < -7\) or \(2x + 5 \ge 11\). Solve each separately: \(3x < -6\) gives \(x < -2\); \(2x \ge 6\) gives \(x \ge 3\). A number satisfies the compound statement if it satisfies either part, so the solution set is the union
"And" corresponds to intersection (the overlap of the two solution sets); "or" corresponds to union (everything covered by either). An "and" can be empty: \(x < 3\) and \(x > 5\) share no numbers, so its solution set is \(\varnothing\).
|
Impossible sandwiches
Never write an "or" as a sandwich. "\(x < -2\) or \(x \ge 3\)" is not \(3 \le x < -2\); that sandwich says \(x\) is simultaneously at least 3 and less than \(-2\), which is impossible. A double inequality \(a < x < b\) only makes sense when \(a < b\), and it always means "and". |
5.6.9. Where you’d use this
Inequalities answer "how much can I afford?", "how many will fit?" and "what do I need?".
-
Grades. Your four test scores average 78 and the final test counts the same as each of the others. What score \(s\) lifts your average to at least 80? The five scores total \(4 \times 78 + s = 312 + s\), so \(\frac{312 + s}{5} \ge 80\), giving \(312 + s \ge 400\) and \(s \ge 88\).
-
Engineering limits. A lift is rated for 1000 kg. The operator weighs 80 kg and each crate 35 kg. The number of crates \(n\) must satisfy \(80 + 35n \le 1000\), so \(n \le 26.29\ldots\). Because \(n\) is a whole number, the answer is at most 26. Rounding down is forced by the direction of the inequality; rounding to the nearest integer would not be safe here.
-
Computing: frame budgets. A game running at 60 frames per second has \(1000/60 \approx 16.67\) ms per frame. If fixed work takes 4 ms and each sprite costs 0.05 ms, the sprite count must satisfy \(4 + 0.05n \le 16.67\), so \(n \le 253\). Performance budgets for web pages, database queries and network requests are the same one-line inequality.
|
Why numbering should start at zero
In a famous one-page note, EWD831 (1982), Edsger Dijkstra argued that the best way to describe the sequence \(2, 3, \dots, 12\) is \(2 \le i < 13\), a half-open interval, because adjacent ranges then share an endpoint, the length is the difference of the bounds, and an empty range \(a \le i < a\) needs no special case. From that he concluded that indexing should start at zero, so that a sequence of length \(N\) is indexed by \(0 \le i < N\). The symbols \(<\) and \(>\) themselves are much older: they first appeared in print in Thomas Harriot’s Artis Analyticae Praxis (1631). |
|
Inequality explorer
A slider sets \(k\); the display shows two points \(a < b\) on a number line and their images \(ka\) and \(kb\). As \(k\) passes through 0 the images collide and then swap order, making the sign-flip rule visible. A second panel lets the learner type an inequality and drag a test point, which turns green inside the solution set and red outside. |
5.7. Exercises: inequalities
-
Write in interval notation: (a) \(x \ge -3\) (b) \(-1 < x \le 6\) (c) \(x < 0\) or \(x > 2\).
-
Solve \(5 - 2x > 11\) and give the interval.
-
Solve \(-4 \le \dfrac{3x - 1}{2} < 7\).
-
Solve \(2x + 1 < -5\) or \(3 - x \le 1\).
-
Explain why "\(x < 3\) and \(x > 5\)" has no solutions, while "\(x < 3\) or \(x > 5\)" has infinitely many.
-
Find every integer \(i\) with \(-7 < 5 - 4i \le 13\).
Answers
-
(a) \(\lbrack -3, \infty)\) (b) \((-1, 6]\) (c) \((-\infty, 0) \cup (2, \infty)\).
-
Subtract 5: \(-2x > 6\). Divide by \(-2\) and flip: \(x < -3\). Interval \((-\infty, -3)\). Test \(x = -4\): \(5 + 8 = 13 > 11\), true.
-
Multiply all parts by 2: \(-8 \le 3x - 1 < 14\). Add 1: \(-7 \le 3x < 15\). Divide by 3: \(-\tfrac73 \le x < 5\). Interval \(\lbrack -\tfrac73, 5)\).
-
First: \(2x < -6\), \(x < -3\). Second: \(-x \le -2\), \(x \ge 2\). Union: \((-\infty, -3) \cup [2, \infty)\).
-
No number is both below 3 and above 5, so the intersection is empty. The union contains every number below 3 and every number above 5.
-
Subtract 5: \(-12 < -4i \le 8\). Divide by \(-4\), flipping both: \(3 > i \ge -2\), i.e. \(-2 \le i < 3\). Integers: \(-2, -1, 0, 1, 2\). Check \(i = 3\): \(5 - 12 = -7\), and \(-7 < -7\) is false, so 3 is correctly excluded.
5.8. Absolute-value equations and inequalities
5.8.1. The problem
A machined bolt should be 25.00 mm long, with a tolerance of 0.05 mm. Which lengths \(L\) pass inspection? In words: "\(L\) is within 0.05 of 25". In symbols:
Absolute values are the language of distance, error and tolerance. They look awkward because the absolute-value function is not linear (it has a corner), but every absolute-value equation or inequality with a linear inside splits into linear pieces you already know how to solve.
|
Absolute value as distance
The absolute value \(|x|\) is the distance from \(x\) to 0 on the number line, so it is never negative: \(|5| = 5\), \(|-5| = 5\), \(|0| = 0\). Formally,
\[|x| = \begin{cases} x & \text{if } x \ge 0,\\ -x & \text{if } x < 0. \end{cases}\]
(The second line is not a typo: if \(x\) is negative, \(-x\) is positive.) More usefully, \(|x - a|\) is the distance between \(x\) and \(a\). Read \(|x - 3| < 2\) as "\(x\) is less than 2 away from 3". |
5.8.2. Intuition
Read every absolute-value statement as a distance statement and the answer is almost visible:
-
\(|x - 3| = 2\): the points at distance exactly 2 from 3, namely \(1\) and \(5\).
-
\(|x - 3| < 2\): the points closer than 2 to 3, namely the open interval \((1, 5)\).
-
\(|x - 3| > 2\): the points farther than 2 from 3, namely \((-\infty, 1) \cup (5, \infty)\).
"Less than" gives one interval in the middle (an "and"); "greater than" gives two outer rays (an "or"). This is the whole theory, and it follows directly from the definition: \(|u| = k\) with \(k > 0\) means \(u\) is either \(k\) or \(-k\); \(|u| < k\) means \(u\) is between \(-k\) and \(k\).
The same holds with \(\le\) and \(\ge\). If \(k < 0\), \(|u| = k\) and \(|u| < k\) have no solutions (a distance cannot be negative), while \(|u| > k\) is true for every \(u\).
5.8.3. The method
Input: an equation or inequality containing one absolute value \(|ax + b|\).
Steps:
-
Isolate the absolute value: rearrange to \(|ax + b| \;\square\; k\), where \(\square\) is \(=\), \(<\), \(\le\), \(>\) or \(\ge\).
-
Check the sign of \(k\). If \(k < 0\): \(=\), \(<\), \(\le\) have no solution; \(>\), \(\ge\) hold for all \(x\). If \(k = 0\), the equation becomes \(ax + b = 0\).
-
Split into linear pieces:
-
\(=\): solve \(ax + b = k\) and \(ax + b = -k\).
-
\(<\) or \(\le\): solve the double inequality \(-k < ax + b < k\).
-
\(>\) or \(\ge\): solve \(ax + b > k\) or \(ax + b < -k\).
-
-
Solve each linear piece with the earlier procedures, flipping for negative multipliers.
-
Combine and check.
Output: a set of at most two numbers (equations), an interval ("less than"), or a union of two rays ("greater than").
5.8.4. Worked examples
Example 1. Solve \(3|x - 1| + 2 = 14\).
Check: \(3|4| + 2 = 14\) and \(3|-4| + 2 = 14\). Both work. (Geometrically: the two points at distance 4 from 1.)
Example 2. Solve \(|2x - 5| = 7\).
\(2x - 5 = 7\) gives \(x = 6\); \(2x - 5 = -7\) gives \(2x = -2\), \(x = -1\). Check: \(|7| = 7\) and \(|-7| = 7\).
Example 3. Solve \(|2x + 1| \ge 5\).
Solution set \((-\infty, -3] \cup [2, \infty)\). Test \(x = 0\), which should fail: \(|1| = 1 \ge 5\) is false. Good.
Example 4. The bolt: \(|L - 25| \le 0.05\) becomes \(-0.05 \le L - 25 \le 0.05\), so \(24.95 \le L \le 25.05\).
5.8.5. Alternative approaches
-
Distance reading. When the inside is \(x - a\) (coefficient 1), skip the algebra: \(|x + 4| < 3\) is \(|x - (-4)| < 3\), "within 3 of \(-4\)", so \((-7, -1)\).
-
Case analysis on the sign of the inside. Use the piecewise definition: if \(2x - 5 \ge 0\) then \(|2x - 5| = 2x - 5\); otherwise it is \(-(2x - 5)\). Solve in each case and keep only solutions consistent with the case. Slower, but it is the only method that works for equations with two absolute values or with \(x\) outside too, such as \(|x - 1| = 2x + 4\).
-
Squaring. Since both sides are non-negative, \(|u| = k \Leftrightarrow u^2 = k^2\). This produces a quadratic, so it is heavier machinery; but it is the natural method for \(|x - 1| = |x - 5|\), where squaring both sides cancels the \(x^2\) terms: \(x^2 - 2x + 1 = x^2 - 10x + 25\), so \(8x = 24\), \(x = 3\). (Geometrically: the point equidistant from 1 and 5 is the midpoint 3.)
Choosing: use the distance reading for \(|x - a|\) forms, the split procedure for a single \(|ax + b|\) isolated on one side, and case analysis whenever \(x\) also appears outside the absolute value. Whenever \(x\) appears outside, check every candidate in the original equation, because the right side might be negative.
|
Absolute-value traps
|
5.8.6. Where you’d use this
Any range \(\lbrack a, b]\) can be written as one absolute-value inequality: centre \(c = \frac{a + b}{2}\), half-width \(r = \frac{b - a}{2}\), and \(a \le x \le b \iff |x - c| \le r\). That is how specifications, tolerances and error bars are quoted.
-
Health. A target range of 4 to 7 mmol/L for blood glucose is \(|G - 5.5| \le 1.5\): "within 1.5 of 5.5".
-
Science. A measurement reported as \(g = 9.81 \pm 0.02\ \text{m/s}^2\) means \(|g - 9.81| \le 0.02\). Two experiments agree if their ranges overlap; with \(9.81 \pm 0.02\) and \(9.86 \pm 0.02\) they do not, since \(|9.86 - 9.81| = 0.05 > 0.02 + 0.02\).
-
Manufacturing. The bolt above: \(|L - 25| \le 0.05\) is the interval \(\lbrack 24.95, 25.05]\) mm.
-
Games and graphics. Two boxes overlap horizontally exactly when the distance between their centres is less than the sum of their half-widths: \(|c_1 - c_2| < \frac{w_1 + w_2}{2}\). With centres at 10 and 16 and widths 4 and 6, \(|10 - 16| = 6\) is not less than \(5\), so there is no collision. Do the same test in \(y\) and you have the axis-aligned bounding-box (AABB) check at the heart of most collision detection.
5.9. Exercises: absolute value
-
Solve \(|x + 2| = 5\).
-
Solve \(|3x - 6| \le 9\).
-
Solve \(|1 - 2x| > 3\).
-
Solve \(2|x - 4| + 3 = 1\).
-
Write "\(x\) is within 0.5 of 7" as an absolute-value inequality and as an interval.
-
Solve \(|x - 1| = |x - 5|\) by splitting rather than squaring. Interpret the answer as a distance.
Answers
-
\(x + 2 = 5\) or \(x + 2 = -5\): \(x = 3\) or \(x = -7\). (The points at distance 5 from \(-2\).)
-
\(-9 \le 3x - 6 \le 9\); add 6: \(-3 \le 3x \le 15\); divide by 3: \(-1 \le x \le 5\). Interval \(\lbrack -1, 5]\).
-
\(1 - 2x > 3\) or \(1 - 2x < -3\). First: \(-2x > 2\), \(x < -1\). Second: \(-2x < -4\), \(x > 2\). Solution \((-\infty, -1) \cup (2, \infty)\).
-
\(2|x - 4| = -2\), so \(|x - 4| = -1\). An absolute value cannot be negative: no solution, \(\varnothing\).
-
\(|x - 7| \le 0.5\), i.e. \(\lbrack 6.5, 7.5]\).
-
Two absolute values are equal when the insides are equal or opposite. \(x - 1 = x - 5\) gives \(-1 = -5\), impossible. \(x - 1 = -(x - 5)\) gives \(2x = 6\), \(x = 3\). The point equidistant from 1 and 5 is their midpoint, 3.
5.10. The straight line: \(y = mx + b\)
5.10.1. The problem
So far the unknown has been a single number to be found. Step back and ask a bigger question about the taxi: how does the fare depend on the distance, for every distance? Tabulate it:
| distance \(d\) (miles) | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
fare \(C\) ($) |
3.00 |
5.50 |
8.00 |
10.50 |
13.00 |
Each extra mile adds the same $2.50. That constant step is the defining feature of a linear relationship, and it is why the graph is a straight line. Every equation you solved earlier in this chapter was a question about a line; seeing the line makes the algebra visible.
5.10.2. Intuition: constant rate of change
A relationship \(y = mx + b\) has two numbers that say everything about it.
-
\(b\) is the starting value: the value of \(y\) when \(x = 0\). For the taxi, \(b = 3\), the flag-fall fee.
-
\(m\) is the rate of change: how much \(y\) changes for each unit increase in \(x\). For the taxi, \(m = 2.5\) dollars per mile.
Rate of change is the idea to hold on to. Speed is a rate of change (miles per hour), price is a rate of change (dollars per kilogram), throughput is a rate of change (requests per second). A linear model says the rate is the same everywhere. Calculus (Chapter 17) is, in large part, about what to do when it is not.
|
Slope, gradient, intercept
In \(y = mx + b\) (the slope–intercept form):
The slope has units: units of \(y\) per unit of \(x\). |
|
Delta notation
\(\Delta\) (capital Greek delta) means "change in". \(\Delta x = x_2 - x_1\) is the change in \(x\) from a first point \((x_1, y_1)\) to a second \((x_2, y_2)\); the subscripts 1 and 2 simply label the points. \(\Delta y = y_2 - y_1\). Slope is "rise over run":
\[m = \frac{\Delta y}{\Delta x} = \frac{y_2 - y_1}{x_2 - x_1}, \qquad x_1 \neq x_2.\]
|
5.10.3. Why it works: the slope is the same everywhere
Why does \(y = mx + b\) give a straight line, and why is the slope the same whichever two points you pick? Take any two points on the graph, at \(x_1\) and \(x_2\). Then
The \(b\) cancels and the ratio is always \(m\). So every "rise over run" triangle drawn on the graph has the same shape (the triangles are similar, in the language of Chapter 9), and a curve whose rise-over-run triangles all have the same shape cannot bend: it is a straight line. Conversely, any non-vertical line has a constant ratio \(\Delta y / \Delta x\), which is exactly what \(y = mx + b\) encodes.
5.10.4. Three forms of a line’s equation
The same line can be written in several forms, each convenient for a different job.
| Form | Equation | Best when you know… |
|---|---|---|
slope–intercept |
\(y = mx + b\) |
the slope and the \(y\)-intercept; for graphing and evaluating |
point–slope |
\(y - y_1 = m(x - x_1)\) |
the slope and any one point \((x_1, y_1)\) |
standard (general) |
\(Ax + By = C\) |
nothing in particular; it treats \(x\) and \(y\) symmetrically and is the form used for systems (Chapter 6) |
Point–slope form is just the slope definition rearranged: if \((x, y)\) is any other point on the line, then \(\frac{y - y_1}{x - x_1} = m\); multiply both sides by \((x - x_1)\).
Input: two points \((x_1, y_1)\) and \((x_2, y_2)\).
Steps:
-
If \(x_1 = x_2\), the line is vertical: its equation is \(x = x_1\). Stop.
-
Compute the slope \(m = \dfrac{y_2 - y_1}{x_2 - x_1}\), subtracting in the same order top and bottom.
-
Substitute into point–slope form: \(y - y_1 = m(x - x_1)\).
-
Expand and add \(y_1\) to get slope–intercept form \(y = mx + b\).
-
Check that the other point satisfies the equation.
Output: the equation of the line.
5.10.5. Worked example
Find the line through \((2, 1)\) and \((6, 7)\), and its intercepts.
Check with the other point: \(\tfrac32 \cdot 6 - 2 = 9 - 2 = 7\). Correct.
The \(y\)-intercept is \((0, -2)\). The \(x\)-intercept solves a linear equation:
In standard form, multiply \(y = \tfrac32 x - 2\) by 2 and rearrange: \(3x - 2y = 4\).
5.10.6. Special lines, parallel and perpendicular
-
Horizontal lines have slope 0: \(y = k\). The output never changes.
-
Vertical lines have undefined slope (the run is zero, and division by zero is undefined): \(x = k\). A vertical line is not of the form \(y = mx + b\) at all, which is one reason standard form \(Ax + By = C\) exists: it covers vertical lines with \(B = 0\).
-
Parallel lines have equal slopes. The line through \((2, 3)\) parallel to \(y = 4x - 1\) is \(y - 3 = 4(x - 2)\), i.e. \(y = 4x - 5\).
-
Perpendicular lines (neither vertical) have slopes whose product is \(-1\): \(m_1 m_2 = -1\). So a line perpendicular to slope \(\tfrac32\) has slope \(-\tfrac23\). Why this is so is a pleasant piece of geometry, done in Chapter 10.
5.10.7. Equations and inequalities, seen on the line
Here is the payoff: every technique in this chapter has a picture.
-
Solving \(mx + b = 0\) is finding where the line crosses the \(x\)-axis.
-
Solving \(mx + b = k\) is finding where the line meets the horizontal line \(y = k\).
-
Solving \(mx + b > 0\) is finding where the line is above the axis. A rising line (\(m > 0\)) is above the axis to the right of its \(x\)-intercept; a falling line (\(m < 0\)) is above it to the left. That is the sign-flip rule again, now as a picture: dividing by a negative slope reverses the direction of the answer.
-
Solving \(ax + b = cx + d\) is finding where two lines cross; the "no solution" and "all solutions" cases are parallel and coincident lines.
-
Solving \(|x - a| < r\) is finding where the V-shaped graph \(y = |x - a|\) dips below the horizontal line \(y = r\).
|
Slope pitfalls
|
5.10.8. Where you’d use this
A slope is a rate: "so much output per unit of input". Once you look for it, it is everywhere.
-
Travel and building. A road sign reading "10%" means a slope of \(0.1\): 10 m of climb per 100 m horizontally. Accessibility guidelines in the US and UK limit wheelchair ramps to about 1 in 12 (slope \(\tfrac{1}{12}\)), so a 0.6 m step needs a ramp at least \(0.6 \times 12 = 7.2\) m long.
-
Mechanics. On a velocity–time graph the slope is the acceleration and the intercept is the initial velocity. A car doing 4 m/s at \(t = 0\) and 16 m/s at \(t = 6\) s has slope \(\frac{16 - 4}{6 - 0} = 2\ \text{m/s}^2\), so \(v = 4 + 2t\): exactly \(v = u + at\). Hooke’s law (\(F = kx\)) and Ohm’s law (\(V = IR\)) are lines through the origin whose slopes are the spring constant and the resistance.
-
Computing. The simplest machine-learning model, linear regression with one input, is \(y = mx + b\): the training data choose the slope (the weight) and the intercept (the bias). A single artificial neuron is the same formula before its activation function (Chapter 33).
|
Who chose \(m\)?
Nobody knows why American textbooks use \(m\) for slope. Popular explanations (French monter, "to climb"; "modulus of slope") are unsupported by evidence; the letter appears in 19th-century English and American texts without explanation. British texts use \(y = mx + c\), some European ones \(y = kx + d\) or \(y = ax + b\). The idea matters; the letter does not. |
|
Slope and intercept sliders
Sliders for \(m\) and \(b\) redraw \(y = mx + b\) live, with a draggable rise–run triangle whose size changes while its ratio stays fixed. A second mode shows two draggable points; the line through them and its three equation forms update as the points move. A third mode shades the region where \(mx + b > k\) on the \(x\)-axis. Try it: Slide m and b |
5.11. Exercises: lines
-
Find the slope, \(y\)-intercept and \(x\)-intercept of \(3x + 2y = 12\).
-
Find the equation of the line through \((-1, 4)\) and \((3, -4)\).
-
Find the line through \((2, 3)\) perpendicular to \(y = \tfrac12 x + 7\).
-
A taxi charges $3.50 plus $2.20 per mile. Write the fare as a linear function of distance, and find the greatest distance you can afford with $25.
-
A table shows \(x = 0, 2, 4\) and \(y = 5, 11, 17\). Is the relationship linear? If so, find its equation and decide whether \((10, 34)\) fits.
Answers
-
\(2y = -3x + 12\), so \(y = -\tfrac32 x + 6\): slope \(-\tfrac32\), \(y\)-intercept \((0, 6)\). Setting \(y = 0\): \(3x = 12\), \(x\)-intercept \((4, 0)\).
-
\(m = \frac{-4 - 4}{3 - (-1)} = \frac{-8}{4} = -2\). \(y - 4 = -2(x + 1)\), so \(y = -2x + 2\). Check \((3, -4)\): \(-6 + 2 = -4\).
-
The perpendicular slope is \(-1 \div \tfrac12 = -2\). \(y - 3 = -2(x - 2)\), so \(y = -2x + 7\).
-
\(C = 3.5 + 2.2d\). Solve \(3.5 + 2.2d \le 25\): \(2.2d \le 21.5\), \(d \le 21.5/2.2 \approx 9.77\). So up to about 9.77 miles (with \(d \ge 0\)).
-
Each step of 2 in \(x\) adds 6 to \(y\): constant rate, so linear, with \(m = 3\) and \(b = 5\): \(y = 3x + 5\). At \(x = 10\), \(y = 35\), so \((10, 34)\) does not fit.
5.12. Modelling: word problems as linear equations
5.12.1. The problem
Real problems do not arrive as equations. They arrive as sentences, tables, invoices, and requirements. The mathematical skill is translation: deciding what the unknown is, expressing every quantity in terms of it, and recognising which statement is the equation. The solving, by now, is the easy part.
Input: a problem described in words.
Steps:
-
Name the unknown in a full sentence with units: "Let \(t\) be the number of hours after 9:00 that the first cyclist has been riding." Vague definitions ("let \(t\) = time") cause most errors.
-
Express every other quantity in terms of the unknown, keeping units consistent (do not mix minutes with hours, or percentages with fractions).
-
Find the equality or inequality the problem asserts ("catches up" means equal distances; "is cheaper" means one cost is less than the other).
-
Solve with the procedures of this chapter.
-
Check the answer against the original words, not just the equation.
-
Interpret: answer the question actually asked, with units and a sentence.
Output: the answer, in context.
5.12.2. Worked example 1: rates (catching up)
Cyclist A leaves at 9:00 riding at 12 km/h. Cyclist B leaves from the same place at 9:30 on the same route at 18 km/h. When and where does B catch A?
Let \(t\) be the number of hours after 9:00. A has ridden for \(t\) hours and B for \(t - 0.5\) hours (30 minutes later, in hours). Distance is speed times time, and "catches" means equal distances:
Check: by then A has ridden 1.5 h at 12 km/h, i.e. 18 km; B has ridden 1 h at 18 km/h, i.e. 18 km. Interpret: B catches A at 10:30, 18 km from the start.
5.12.3. Worked example 2: mixtures
How many litres of a 30% acid solution must be added to 10 litres of a 10% solution to obtain a 25% solution?
Let \(x\) be the litres of 30% solution added. The key is to track the quantity that is conserved: pure acid.
| litres | acid fraction | litres of acid | |
|---|---|---|---|
10% solution |
10 |
0.10 |
1 |
30% solution |
\(x\) |
0.30 |
\(0.3x\) |
mixture |
\(10 + x\) |
0.25 |
\(0.25(10 + x)\) |
Acid in = acid out:
Check: 40 litres containing \(1 + 9 = 10\) litres of acid is \(10/40 = 25\%\). Interpret: add 30 litres. The same table structure solves blends of coffee by price, alloys by purity, and investments by interest rate: a weighted average is a linear equation.
5.12.4. Worked example 3: cost models and break-even
A mobile provider offers Plan A at $20 per month plus $3 per GB, and Plan B at $50 per month plus $1 per GB. When is each plan cheaper?
Let \(g\) be the GB used in a month. The costs are \(C_A = 20 + 3g\) and \(C_B = 50 + g\). The break-even point is where they are equal:
At 15 GB both cost \(20 + 45 = 65\) dollars. Plan A is cheaper when \(20 + 3g < 50 + g\), i.e. \(2g < 30\), i.e. \(g < 15\). Interpret: below 15 GB a month choose A, above 15 GB choose B.
This shape, a fixed cost plus a marginal cost per unit, is the single most common model in business, and the comparison is always the same: the plan with higher fixed cost and lower marginal cost wins at high volume. (Strictly, finding the crossing of two lines is a system of two equations; Chapter 6 develops that view.)
|
Modelling pitfalls
|
|
Where Celsius meets Fahrenheit
Temperature conversion is linear: \(F = \tfrac95 C + 32\). Is there a temperature at which both scales read the same? Set \(F = C\): \(C = \tfrac95 C + 32\), so \(-\tfrac45 C = 32\), so \(C = -40\). At \(-40^\circ\) the two scales agree, which is why Arctic weather reports sometimes do not bother to say which scale they mean. Two lines with different slopes always meet exactly once. |
5.13. Linear interpolation
5.13.1. The problem
A weather station logs 12 °C at 10:00 and 20 °C at 14:00. What was the temperature at 11:30? An animation moves a sprite from \(x = 100\) at frame 0 to \(x = 400\) at frame 60. Where is it at frame 45? A lookup table gives a sensor’s calibration at a few points; what does a reading between two entries mean?
All three ask for a value between two known values, assuming the quantity changes at a constant rate in between. That is linear interpolation, known in graphics and game programming as lerp.
5.13.2. Intuition and derivation
Interpolating means walking along the straight line from one known value \(a\) to the other, \(b\). Describe your position by the fraction of the way you have gone, \(t\): \(t = 0\) at the start, \(t = 1\) at the end, \(t = 0.5\) halfway. The total change is \(b - a\), so after a fraction \(t\) of the journey you have covered \(t(b - a)\) of it:
The two forms are equal by expanding: \(a + tb - ta = (1 - t)a + tb\). The second form shows lerp as a weighted average: weight \(1 - t\) on \(a\), weight \(t\) on \(b\), weights summing to 1. It works unchanged for points, colours, and vectors: lerp each coordinate.
The inverse question, "what fraction of the way is the value \(v\)?", is a linear equation in \(t\):
Combine the two and you can remap a value from one range \(\lbrack a, b]\) to another \(\lbrack c, d]\): find \(t\) in the first range, then lerp in the second.
Input: two known data points \((x_0, y_0)\) and \((x_1, y_1)\) with \(x_0 \neq x_1\), and a query \(x\).
Steps:
-
Compute the fraction \(t = \dfrac{x - x_0}{x_1 - x_0}\) (inverse lerp).
-
If \(t < 0\) or \(t > 1\), you are extrapolating, not interpolating; decide whether that is acceptable, or clamp \(t\) to \(\lbrack 0, 1]\).
-
Compute \(y = y_0 + t\,(y_1 - y_0)\) (lerp).
Output: the estimate \(y\) at \(x\).
5.13.3. Worked example
Temperature at 11:30, given 12 °C at 10:00 and 20 °C at 14:00. Measure time in hours: \(x_0 = 10\), \(x_1 = 14\), \(x = 11.5\).
The estimate is 15 °C. This is exactly the same as finding the line through \((10, 12)\) and \((14, 20)\) (slope 2 °C per hour) and evaluating it at 11.5: \(12 + 2 \cdot 1.5 = 15\). Interpolation is just "the equation of the line through two points", packaged for repeated use.
def lerp(a, b, t):
"""Point a fraction t of the way from a to b (t=0 -> a, t=1 -> b)."""
return a + t * (b - a)
def inverse_lerp(a, b, v):
"""Which t gives lerp(a, b, t) == v? Solves a linear equation for t."""
if a == b:
raise ValueError("a and b must differ")
return (v - a) / (b - a)
def remap(v, in_lo, in_hi, out_lo, out_hi):
"""Map v from one range to another, linearly."""
return lerp(out_lo, out_hi, inverse_lerp(in_lo, in_hi, v))
print(lerp(10, 30, 0.25)) # 15.0
print(inverse_lerp(10, 30, 15)) # 0.25
print(remap(25, 0, 100, 32, 212)) # 25 C in F -> 77.0
print(remap(512, 0, 1023, 0, 3.3)) # 10-bit ADC reading -> volts
15.0 0.25 77.0 1.6516129032258065
remap is the Celsius–Fahrenheit conversion in disguise (0 °C ↦ 32 °F, 100 °C ↦ 212 °F) and the standard way to turn a raw sensor reading into physical units.
5.13.4. Alternatives, choices and failure modes
Linear interpolation is the simplest member of a family. When data are smooth and you have more than two points, polynomial or spline interpolation (Chapter 7, Chapter 32) follows curves better; when data are noisy, fitting a line by regression (Chapter 31) beats passing exactly through two noisy points. Choose lerp when the points are close together relative to how quickly the quantity curves, when speed matters (it is one multiply and two adds), or when "straight-line between keyframes" is the behaviour you actually want.
|
Interpolation pitfalls
|
|
Curves made of straight lines
The smooth Bézier curves in every font and vector drawing are built from nothing but lerps. Given three control points \(P_0, P_1, P_2\), lerp \(P_0 \to P_1\) and \(P_1 \to P_2\) at the same \(t\), then lerp between those two results at \(t\) again. As \(t\) runs from 0 to 1 the final point traces a parabola. This is de Casteljau’s algorithm, developed by Paul de Casteljau at Citroën around 1959 for designing car bodies. |
|
Lerp playground
Drag two points and a slider for \(t\) from \(-0.5\) to \(1.5\); the interpolated point moves along the line, turning red when it leaves \(\lbrack 0, 1]\) (extrapolation). A second panel adds a third control point and shows the nested lerps of de Casteljau’s construction tracing a Bézier curve. |
5.14. Exercises: modelling and interpolation
-
A rectangle has perimeter 46 cm and its length is 5 cm more than its width. Find its dimensions.
-
A shop blends coffee costing $12/kg with coffee costing $20/kg to make 40 kg of a blend selling at $15/kg (with no change in total value). How much of each?
-
A gym charges a $40 joining fee and $25 a month. A rival charges no joining fee and $33 a month. After how many whole months is the first gym cheaper in total?
-
A colour channel fades from 40 to 240. What is its value at \(t = 0.3\)? At what \(t\) does it reach 190?
-
A 10-bit temperature sensor reports integers 0 to 1023, mapping linearly onto \(-40\) °C to 125 °C. What temperature does a reading of 620 represent?
Answers
-
Let \(w\) be the width in cm; length \(w + 5\). \(2(w + w + 5) = 46\), so \(4w + 10 = 46\), \(w = 9\). Dimensions 9 cm by 14 cm. Check: \(2(9 + 14) = 46\).
-
Let \(x\) be the kg at $12; then \(40 - x\) kg at $20. Value: \(12x + 20(40 - x) = 15 \cdot 40 = 600\). Expand: \(12x + 800 - 20x = 600\), so \(-8x = -200\), \(x = 25\). Blend 25 kg of the $12 coffee with 15 kg of the $20 coffee. Check: \(300 + 300 = 600\).
-
After \(n\) months: \(40 + 25n < 33n\) gives \(40 < 8n\), \(n > 5\). At 5 months both total $165; from month 6 on the first gym is cheaper (month 6: $190 versus $198).
-
\(40 + 0.3(240 - 40) = 40 + 60 = 100\). Inverse: \(t = (190 - 40)/(240 - 40) = 150/200 = 0.75\).
-
\(t = 620/1023\); temperature \(-40 + \tfrac{620}{1023} \cdot 165 = -40 + \tfrac{102300}{1023} = -40 + 100 = 60\) °C.
5.15. Interactive tools
Browser tools on the companion website that go with this chapter. Each example link in the chapter opens one of them with that example already set up.
5.16. Mastery check
-
Solve \(4(3 - x) + 2x = 5x - 9\).
-
Solve \(\dfrac{x - 2}{3} + \dfrac{x + 1}{2} = 4\).
-
Find the solution set of \(6x - 2(3x + 1) = -2\). What kind of equation is it?
-
Solve \(-2 < 4 - 3x \le 10\) and write the answer in interval notation.
-
Solve \(|2x - 3| \ge 7\).
-
Find the equation of the line through \((1, -2)\) parallel to \(2x - y = 5\), and its \(x\)-intercept.
-
An animation moves an object from \(x = 100\) at frame 0 to \(x = 400\) at frame 60. Where is it at frame 45, and at which frame does it first pass \(x = 180\)?
Decision rule: All correct without hesitation → move on to Chapter 6. Stuck on 1–3 → reread Section 5.2, Section 5.3 and Section 5.4. Stuck on 4–5 → reread Section 5.6 and Section 5.8. Stuck on 6–7 → reread Section 5.10 and Section 5.13. Stuck on more than three → work the section exercises before continuing.
Mastery check answers
-
Expand: \(12 - 4x + 2x = 5x - 9\), so \(12 - 2x = 5x - 9\). Add \(2x\) and 9: \(21 = 7x\), \(x = 3\). Check: left \(4(0) + 6 = 6\), right \(15 - 9 = 6\).
-
Multiply by 6: \(2(x - 2) + 3(x + 1) = 24\), so \(2x - 4 + 3x + 3 = 24\), \(5x - 1 = 24\), \(x = 5\). Check: \(\tfrac33 + \tfrac62 = 1 + 3 = 4\).
-
\(6x - 6x - 2 = -2\), i.e. \(-2 = -2\): an identity. Solution set \(\mathbb{R}\) (all real numbers).
-
Subtract 4: \(-6 < -3x \le 6\). Divide by \(-3\), flipping both: \(2 > x \ge -2\), i.e. \(-2 \le x < 2\). Interval \(\lbrack -2, 2)\).
-
\(2x - 3 \ge 7\) gives \(x \ge 5\); \(2x - 3 \le -7\) gives \(x \le -2\). Solution \((-\infty, -2] \cup [5, \infty)\).
-
\(2x - y = 5\) is \(y = 2x - 5\), slope 2. Through \((1, -2)\): \(y + 2 = 2(x - 1)\), so \(y = 2x - 4\). \(x\)-intercept: \(2x - 4 = 0\), \(x = 2\), the point \((2, 0)\).
-
Frame 45: \(t = 45/60 = 0.75\), position \(100 + 0.75 \cdot 300 = 325\). For \(x = 180\): \(t = (180 - 100)/300 = 80/300 \approx 0.267\), frame \(0.267 \times 60 = 16\). It reaches 180 exactly at frame 16 and passes it from frame 17 on (frame 17 is at \(100 + 300 \cdot \tfrac{17}{60} = 185\)).