Sub topic 10
Writing an Equation from Two Points
Assume you can plot points on a coordinate plane, work with signed numbers and fractions, and solve simple linear equations. In this chapter, you will use two points to find a line’s slope and then write the line in slope-intercept form:
y = mx + b
Here, m is the slope and b is the y-intercept.
The two-step method
Suppose a line passes through the points (x₁, y₁) and (x₂, y₂).
- Find the slope:
m = (y₂ - y₁) / (x₂ - x₁)
- Use one point and the slope to find
b:
b = y₁ - mx₁
- Substitute
mandbintoy = mx + b.
The order of the points does not matter, as long as you keep each x-value paired with its own y-value and use the same order in the numerator and denominator.
Worked example
Find the equation of the line through (1, 3) and (3, 7).
First, calculate the slope:
m = (7 - 3) / (3 - 1) = 4 / 2 = 2
Now use (1, 3) to find the y-intercept:
b = y₁ - mx₁
b = 3 - 2(1) = 1
Therefore, the equation is:
y = 2x + 1
Check the second point. If x = 3, then:
y = 2(3) + 1 = 7
The equation gives the correct y-value, so both points lie on the line.
You could also use (3, 7) to find b:
b = 7 - 2(3) = 1
The same intercept appears because both points belong to the same line.
A direct substitution method
Instead of finding b separately, substitute the known slope and one point into y = mx + b.
Using slope m = 2 and point (1, 3):
3 = 2(1) + b
3 = 2 + b
b = 1
This method is useful when the arithmetic is simple. Writing the equation for b makes the reasoning easier to check.
Special case: a vertical line
If the two points have the same x-coordinate, then x₂ - x₁ = 0. Division by zero is undefined, so the slope does not exist.
For example, the points (4, 1) and (4, 6) form a vertical line. Its equation is:
x = 4
A vertical line cannot be written in slope-intercept form because it has no defined slope.
Checking your equation
After writing an equation, use both original points as a check.
For y = mx + b:
- Substitute the first x-value and verify its y-value.
- Substitute the second x-value and verify its y-value.
- If either check fails, inspect the subtraction in the slope or the calculation of
b.
A common error is using a coordinate from one point with the other point. Keep the pairs together: (x₁, y₁) and (x₂, y₂).
def line_through(x1, y1, x2, y2):
if x1 == x2:
raise ValueError("A vertical line has no slope-intercept form")
m = (y2 - y1) / (x2 - x1)
b = y1 - m * x1
return m, b
m, b = line_through(1, 3, 3, 7)
print(f"y = {m}x + {b}") # y = 2.0x + 1.0Exercise
Find the equation of the line through (-2, 5) and (4, -7). Then check both points in your equation.
Show answer
The slope is m = (-7 - 5) / (4 - (-2)) = -12 / 6 = -2. Using (-2, 5), b = 5 - (-2)(-2) = 1. The equation is y = -2x + 1. It gives y = 5 when x = -2 and y = -7 when x = 4.