Sub topic 3
Reviewing slope
Slope is the number the rest of this tutorial depends on. Parallel lines are the lines with equal slopes. Perpendicular lines are the lines whose slopes are negative reciprocals. This chapter reviews slope so you can compute it quickly and without sign errors, and so you know where it breaks down.
This chapter assumes you can plot points on the coordinate plane, solve a linear equation in one variable, and add, subtract, multiply, and divide fractions, including negative fractions.
What slope measures
Slope is a single number that describes how steep a line is and which way it leans. It compares the vertical change to the horizontal change as you move from one point on the line to another.
- The rise is the change in y, written y₂ − y₁.
- The run is the change in x, written x₂ − x₁.
- The slope m is rise divided by run.
For the points (1, 2) and (4, 8), the rise is 8 − 2 = 6 and the run is 4 − 1 = 3. So m = 6/3 = 2. Moving one unit to the right always moves the line up two units.
Why any two points give the same answer
A straight line has the same slope everywhere. Pick any two points on it, draw a horizontal segment and a vertical segment to form a right triangle, and you get a triangle similar to the one from any other pair of points. Similar triangles have equal side ratios, so rise/run does not change. This fact is what makes slope a property of the line and not of the two points you happened to choose.
Order does not matter, consistency does
You can label the points in either order, but you must subtract in the same order on top and bottom.
Take (3, 5) and (−1, 9).
- Taking (−1, 9) as the second point: (9 − 5) / (−1 − 3) = 4 / −4 = −1.
- Taking (3, 5) as the second point: (5 − 9) / (3 − (−1)) = −4 / 4 = −1.
Both orders give −1. Mixing them gives a wrong answer: (9 − 5) / (3 − (−1)) = 4/4 = 1 has the wrong sign.
Reading the sign and size of a slope
The sign tells you the direction. The size tells you the steepness.
| Slope | What the line does | Example |
|---|---|---|
| Positive | Rises as you move right | m = 2 |
| Negative | Falls as you move right | m = −1/2 |
| Zero | Horizontal, rise is 0 | (0, 4) and (5, 4) give 0/5 = 0 |
| Undefined | Vertical, run is 0 | (2, 3) and (2, 7) give 4/0 |
A larger absolute value means a steeper line. A slope of 3 is steeper than a slope of 1, and a slope of −3 is just as steep as 3 but leans the other way. A slope between −1 and 1 is shallower than a 45° line.
Slope is also linked to angle. If θ is the angle a line makes with the positive x-axis, then m = tan θ. A slope of 1 matches 45°, and a slope of 2 matches about 63.4°. You will not need trigonometry for this tutorial. The link explains why slope 0 means flat and why slope grows without limit as a line approaches vertical.
Finding slope from different information
You will meet lines in several forms. Each one gives you slope in a different way.
From a graph
Choose two points where the line crosses grid intersections exactly. Count the rise (up is positive, down is negative) and the run (right is positive, left is negative). Check the axis scale first. If one grid square is 1 unit on the x-axis and 5 units on the y-axis, count in units, not squares.
From a table of values
Pick two rows and use the same formula. For a straight line, every pair of rows gives the same slope. If two pairs give different slopes, the table does not describe a line.
| x | y |
|---|---|
| 0 | 3 |
| 2 | 7 |
| 5 | 13 |
Rows 1 and 2 give (7 − 3)/(2 − 0) = 2. Rows 2 and 3 give (13 − 7)/(5 − 2) = 2. The slope is 2.
From slope-intercept form
In y = mx + b, the coefficient of x is the slope. For y = −3x + 7, the slope is −3. The equation must be solved for y first. In y = 2 + 4x, the slope is 4, not 2, because the slope is the coefficient of x wherever it appears.
From standard form
Standard form is Ax + By = C. Solve for y:
By = −Ax + C, so y = (−A/B)x + C/B.
The slope is −A/B, which requires B ≠ 0. For 3x + 4y = 12, the slope is −3/4. If B = 0, the equation reduces to x = C/A, which is a vertical line with undefined slope. If A = 0, the equation reduces to y = C/B, which is horizontal with slope 0.
Computing slope exactly in code
Slopes are ratios of integers, so decimals can hide a difference that matters later. In decimal arithmetic, 1/3 is stored as an approximation, and a test such as "are these two slopes equal?" can fail even when they are equal on paper. Python's Fraction type stores the ratio exactly and reduces it to lowest terms.
from fractions import Fraction
def slope(p, q):
(x1, y1), (x2, y2) = p, q
if x1 == x2:
return None # vertical line (or the same point), slope undefined
return Fraction(y2 - y1, x2 - x1)
def slope_from_standard(A, B):
# slope of Ax + By = C
if B == 0:
return None # vertical line x = C/A
return Fraction(-A, B)
print(slope((1, 2), (4, 8))) # 2
print(slope((3, 5), (-1, 9))) # -1
print(slope((-2, 1), (4, -3))) # -2/3
print(slope((0, 4), (5, 4))) # 0
print(slope((2, 3), (2, 7))) # None
print(slope_from_standard(3, 4)) # -3/4The function returns None for a vertical line instead of raising a division error, so the calling code has to handle that case on purpose. The next chapters rely on this: a test such as m1 == m2 must not be run until you have checked for None.
Common errors
- Inconsistent subtraction order. Writing (y₂ − y₁) on top and (x₁ − x₂) on the bottom flips the sign of the answer.
- Run over rise. Slope is rise over run. Inverting it gives the reciprocal, which is a different line unless the slope is 1 or −1.
- Losing a negative sign. When a coordinate is negative, keep parentheses: x₂ − x₁ with x₁ = −4 is 6 − (−4) = 10, not 2.
- Mixing up zero and undefined. A horizontal line has slope 0 because the rise is 0. A vertical line has an undefined slope because the run is 0. Remember that 0/5 is a valid number and 4/0 is not.
- Reading slope off an unsolved equation. In 2y = 6x + 4, the slope is 3, not 6. Divide by 2 first to get y = 3x + 2.
- Counting grid squares on an uneven scale. Use the axis labels, not the number of squares.
- Using the intercept as the slope. In y = 5x − 2, the slope is 5. The −2 is where the line crosses the y-axis.
Why this matters for the next chapters
Two facts from this chapter carry forward.
- A line has exactly one slope, or none if it is vertical. Comparing two lines therefore reduces to comparing two numbers. The test for parallel lines compares them for equality. The test for perpendicular lines checks whether they are negative reciprocals.
- Vertical lines need separate treatment. Any slope test that divides by a run will fail on them, so later chapters handle vertical and horizontal lines as special cases.
Exercise
Find the slope of the line through (−2, 5) and (3, −5). Then say whether the line rises, falls, is horizontal, or is vertical.
Show answer
The rise is −5 − 5 = −10 and the run is 3 − (−2) = 5. The slope is −10/5 = −2. The slope is negative, so the line falls as you move right.
Exercise
Find the slope of each line: (a) y = 2 + 4x, (b) 6x − 3y = 9, (c) 2x = 8.
Show answer
(a) The coefficient of x is 4, so the slope is 4. (b) Here A = 6 and B = −3, so the slope is −A/B = −6/(−3) = 2. Check by solving: −3y = −6x + 9, so y = 2x − 3. (c) This simplifies to x = 4, a vertical line, so the slope is undefined.
Exercise
A table has the rows (1, 4), (3, 10), and (6, 20). Is it a straight line? Show your reasoning.
Show answer
Rows 1 and 2 give (10 − 4)/(3 − 1) = 3. Rows 2 and 3 give (20 − 10)/(6 − 3) = 10/3. The two slopes differ, so the points do not lie on one straight line.