Sub topic 5
Computing Slope from Two Points
Prerequisites
This chapter assumes you can plot ordered pairs on a coordinate plane, work with signed numbers and fractions, and rearrange simple algebraic expressions. An ordered pair is written \((x, y)\), where \(x\) gives the horizontal position and \(y\) gives the vertical position.
Slope measures how much a line changes vertically for each unit it changes horizontally. In other words, slope is a rate of change. If a line rises 3 units while moving right 2 units, its slope is \(3/2\).
The Slope Formula
For two points,
\[ (x1, y1) \quad \text{and} \quad (x2, y2), \]
the slope is
\[ m = \frac{y2-y1}{x2-x1}. \]
The letter \(m\) is commonly used for slope. The numerator, \(y2-y1\), is the change in \(y\), also called the rise. The denominator, \(x2-x1\), is the change in \(x\), also called the run.
The subscripts do not identify a special point. You may choose either point as point 1, as long as you use the same order in both differences.
Worked Example
Find the slope of the line through \((2, 1)\) and \((6, 9)\).
- Assign the coordinates:
- \(x1=2,\ y1=1\)
- \(x2=6,\ y2=9\)
- Substitute into the formula:
\[ m=\frac{9-1}{6-2} \]
- Simplify:
\[ m=\frac{8}{4}=2 \]
The slope is \(2\). The line rises 2 units for every 1 unit it moves right.
You could reverse the points and get the same result:
\[ m=\frac{1-9}{2-6}=\frac{-8}{-4}=2. \]
Both differences change sign, so the quotient remains the same.
Signs and Direction
The sign of the slope describes the line’s direction as you move from left to right.
| Slope | Direction from left to right | Example |
|---|---|---|
| Positive | The line rises | \(m=3\) |
| Negative | The line falls | \(m=-\frac{1}{2}\) |
| Zero | The line is horizontal | \(m=0\) |
| Undefined | The line is vertical | \(x=4\) |
A horizontal line has points with equal \(y\)-values. Its rise is zero, so its slope is \(0\). A vertical line has points with equal \(x\)-values. Its run is zero, and division by zero is undefined.
def slope(x1, y1, x2, y2):
if x1 == x2:
raise ValueError("A vertical line has undefined slope")
return (y2 - y1) / (x2 - x1)
print(slope(1, 2, 3, 6)) # 2.0
print(slope(0, 5, 4, 1)) # -1.0Avoiding Common Errors
The most common mistake is reversing only one difference. For example, this expression mixes the point order:
\[ \frac{y2-y1}{x1-x2}. \]
It produces the opposite sign. Keep the order consistent.
Another mistake is using the coordinates in the wrong position. The \(x\)-values belong in the denominator, and the \(y\)-values belong in the numerator.
Exercise
Find the slope of the line through (-3, 8) and (5, -4). State whether the line rises or falls from left to right.
Show answer
m = (-4 - 8) / (5 - (-3)) = -12 / 8 = -3/2. The negative slope means the line falls from left to right.