Sub topic 3
Writing an equation from a slope and a point
This chapter assumes you can plot points on a coordinate plane, solve one- and two-step linear equations, and work with signed numbers and fractions.
Writing an equation from a slope and a point
A line with slope m through the point (x1, y1) satisfies y - y1 = m(x - x1). Solve this for y to get y = mx + b, where b = y1 - m·x1.
For example, slope 3 through (2, 5) gives b = 5 - 3(2) = -1, so y = 3x - 1.
def intercept_from_slope_point(m, x1, y1):
"""Return b in y = mx + b for a line with slope m through (x1, y1)."""
return y1 - m * x1
m, x1, y1 = 3, 2, 5
b = intercept_from_slope_point(m, x1, y1)
print(f"y = {m}x + ({b})") # y = 3x + (-1)Writing an equation from two points
Find the slope first with m = (y2 - y1) / (x2 - x1). Then use either point to find b.
For (1, 3) and (3, 7), m = 4 / 2 = 2. Using (1, 3), b = 3 - 2(1) = 1. The equation is y = 2x + 1.
Converting from standard form to slope-intercept form
Standard form is Ax + By = C. Solve for y to get y = (-A/B)x + C/B, provided B is not 0. When B = 0, the line is vertical and has no slope-intercept form.
| Standard form | Slope | y-intercept |
|---|---|---|
| 2x + 3y = 6 | -2/3 | 2 |
| x + y = 4 | -1 | 4 |
| 3x - y = 1 | 3 | -1 |
from fractions import Fraction
def standard_to_slope_intercept(A, B, C):
if B == 0:
raise ValueError("B = 0 gives a vertical line with no slope-intercept form")
return Fraction(-A, B), Fraction(C, B)
m, b = standard_to_slope_intercept(2, 3, 6)
print(m, b) # -2/3 2What m and b mean in real situations
In a real situation, m is the rate of change: how much y changes for each one-unit increase in x. The value b is the starting amount when x = 0.
A phone plan that costs $20 plus $5 per gigabyte is C = 5g + 20. The slope 5 means $5 per gigabyte, and the intercept 20 is the base fee.
Parallel and perpendicular lines
Parallel lines have equal slopes. Perpendicular lines have slopes whose product is -1, so each slope is the negative reciprocal of the other. For example, y = 2x + 1 is parallel to y = 2x - 5, and it is perpendicular to y = -1/2 x + 4.
Exercise
Write the equation of the line with slope -4 through the point (2, 1).
Show answer
b = 1 - (-4)(2) = 9, so y = -4x + 9.
Exercise
Is the line 2x + 4y = 8 perpendicular to y = 2x + 1?
Show answer
Yes. Solving for y gives y = -1/2 x + 2, and the slopes 2 and -1/2 have product -1.