Sub topic 1
Quick review: slope as rate of change
Prerequisites
This chapter assumes you can plot points on the coordinate plane, compute slope as rise over run, write slope-intercept form y = mx + b, solve linear equations for one variable, and work with fractions and negative numbers.
Quick review: slope as rate of change
Slope measures how fast y changes when x changes. For two points (x1, y1) and (x2, y2), the slope is m = (y2 - y1) / (x2 - x1). A slope of 2 means y rises 2 units for every 1 unit x moves right.
Where slope-intercept form falls short
Slope-intercept form, y = mx + b, shows the slope and the y-intercept directly. It works well when you already know b. It is awkward when you know a point that is not the y-intercept, because you must solve for b before you can write the equation. Point-slope form avoids that step.
Point-slope form: a line through a known point
Point-slope form is y - y1 = m(x - x1). It uses one known point (x1, y1) and the slope m. Any point on the line can serve as (x1, y1), so you can choose the easiest one.
Writing an equation from a point and a slope
Substitute the point and slope into y - y1 = m(x - x1). For the line through (1, 3) with slope 2, write y - 3 = 2(x - 1). To get standard form, expand and move the x and y terms to the left: 2x - y = -1.
from fractions import Fraction
def slope_through(p, q):
(x1, y1), (x2, y2) = p, q
if x1 == x2:
raise ValueError("vertical line: no slope")
return Fraction(y2 - y1, x2 - x1)
m = slope_through((1, 3), (4, 9))
print(m) # 2Writing an equation from two points
Find the slope with the code above, then use either point in point-slope form. Both points satisfy the same equation, so the choice does not change the result.
> Hmm, a vertical line such as x = 4 has no slope, so this method cannot handle it. Check whether the two x-values match before dividing.
Exercise
Write the equation of the line through (-2, 5) with slope -3 in standard form.
Show answer
Point-slope form gives y - 5 = -3(x + 2). Expanding gives y - 5 = -3x - 6, so y = -3x - 1. Moving terms gives 3x + y = -1. Check: 3(-2) + 5 = -1.