Sub topic 9
Writing an Equation from a Slope and a Point
This chapter assumes you can plot points, compute slope with (y2 - y1) / (x2 - x1), read m and b from y = mx + b, and solve two-step linear equations. It also assumes you can work with signed numbers and fractions. Here you will learn to build the equation of a line when you know its slope and one point on it.
The problem
Suppose a line has slope 3 and passes through (2, 5). You do not know the y-intercept, so you cannot write y = 3x + b yet. The slope fixes the line's tilt. The point pins down where that tilted line sits. Together they determine exactly one line.
Two methods solve this problem:
- Substitute into y = mx + b and solve for b.
- Use point-slope form, y - y1 = m(x - x1).
Both give the same line. The first reuses what you already know. The second skips a step and is often cleaner with fractions.
Method 1: Solve for b
Slope-intercept form is y = mx + b. You know m. A point (x1, y1) on the line makes the equation true, so you can substitute x1 for x and y1 for y. The only unknown left is b.
Worked example: slope 3 through (2, 5)
- Write the form: y = mx + b.
- Substitute m = 3, x = 2, y = 5: 5 = 3(2) + b.
- Simplify: 5 = 6 + b.
- Solve: b = 5 - 6 = -1.
- Write the equation: y = 3x - 1.
Check by substituting the point back in: 3(2) - 1 = 5. The point satisfies the equation.
Worked example with a negative slope and negative coordinates
Find the line with slope -2 through (-4, 1).
- 1 = -2(-4) + b
- 1 = 8 + b
- b = -7
- y = -2x - 7
The usual error here is a sign slip. Multiplying -2 by -4 gives positive 8, not -8. Write the substitution with parentheses around every value so each sign stays visible.
The general derivation
Start with y1 = m·x1 + b. Subtract m·x1 from both sides:
b = y1 - m·x1
This is the formula you can code once and reuse.
from fractions import Fraction
def line_from_slope_point(m, x1, y1):
m = Fraction(m)
b = Fraction(y1) - m * Fraction(x1)
return m, b
def format_line(m, b):
sign = "+" if b >= 0 else "-"
return f"y = {m}x {sign} {abs(b)}"
m, b = line_from_slope_point(3, 2, 5)
print(format_line(m, b)) # y = 3x - 1
m, b = line_from_slope_point(-2, -4, 1)
print(format_line(m, b)) # y = -2x - 7
m, b = line_from_slope_point(Fraction(2, 3), 6, 1)
print(format_line(m, b)) # y = 2/3x - 3Using Fraction keeps results exact. With floats, a slope such as 2/3 would produce a b value like -2.9999999999999996, which is hard to compare or display.
Method 2: Point-slope form
Point-slope form is:
y - y1 = m(x - x1)
It comes straight from the slope definition. Take any point (x, y) on the line and the known point (x1, y1). The slope between them is
(y - y1) / (x - x1) = m
Multiply both sides by (x - x1) and you get point-slope form. The equation also holds at (x1, y1) itself, where both sides are 0.
Worked example: slope 3 through (2, 5)
- Write point-slope form: y - 5 = 3(x - 2).
- Distribute: y - 5 = 3x - 6.
- Add 5 to both sides: y = 3x - 1.
The result matches Method 1.
Worked example with a fractional slope
Find the line with slope 2/3 through (6, 1).
- y - 1 = (2/3)(x - 6)
- y - 1 = (2/3)x - 4
- y = (2/3)x - 3
The 6 cancels the denominator of 2/3, so the fractions stay clean. With Method 1 you would compute 1 = (2/3)(6) + b, which is the same work, but point-slope form lets you leave the equation unsimplified until the end.
Choosing between the methods
| Situation | Better choice | Reason |
|---|---|---|
| The point is the y-intercept, such as (0, 4) | Method 1 | b equals y1 immediately. |
| You only need an equation that is correct, not simplified | Method 2 | You can stop after the first line. |
| Coordinates are negative or fractional | Method 2 | You make fewer steps where a sign can slip. |
| You are coding a function | Method 1 formula | b = y1 - m·x1 is one expression. |
Edge cases
The point is the y-intercept
If the point is (0, y1), then b = y1 - m·0 = y1. For slope 5 through (0, -2), the equation is y = 5x - 2 with no calculation.
Zero slope
With m = 0, the equation is y = y1. Slope 0 through (4, 7) gives y = 7, a horizontal line. Method 1 confirms it: 7 = 0(4) + b, so b = 7.
Undefined slope
A vertical line has no numeric slope, so neither method applies. The line through (3, 2) with undefined slope is x = 3. It has no slope-intercept form, because no single y-value belongs to each x-value. Check for this case before you try to apply a formula.
Point-slope form is not unique in appearance
The same line has many point-slope forms, one for each point on it. For y = 3x - 1, both y - 5 = 3(x - 2) and y + 1 = 3(x - 0) are valid. They look different but describe the same set of points. Once you simplify to slope-intercept form, the answer is unique, which is why graders and software compare that form.
Common errors
- Substituting the point into the wrong variables, such as using x1 where y belongs. Label the point (x1, y1) before you start.
- Forgetting to distribute m across both terms in (x - x1). In y - 5 = 3(x - 2), the right side is 3x - 6, not 3x - 2.
- Moving y1 to the other side with the wrong sign. Adding 5 to both sides cancels the -5 on the left.
- Reporting b without checking. A quick substitution of the original point takes ten seconds and catches most errors.
- Leaving a fractional slope as a decimal. A slope of 2/3 written as 0.67 gives a b that is off by a small amount and a line that misses the point.
A verification routine
Always confirm that your final equation passes through the given point and has the given slope. The code below does this exactly.
from fractions import Fraction
def check(m, b, x1, y1):
return m * x1 + b == y1
m = Fraction(2, 3)
x1, y1 = 6, 1
b = y1 - m * x1
print(b) # -3
print(check(m, b, x1, y1)) # True
# A wrong b is caught immediately
print(check(m, Fraction(-4), x1, y1)) # FalseConnection to what comes next
This skill is the base for writing a line from two points. There you first compute the slope from the points, then apply exactly the procedure in this chapter using either point. It is also the tool for parallel and perpendicular lines: a parallel line shares the slope, a perpendicular line uses the negative reciprocal, and you supply the new line's point to fix its position.
Practice
Exercise
Write the equation of the line with slope -3 that passes through (2, -4). Use Method 1 and show b.
Show answer
Substitute into y = mx + b: -4 = -3(2) + b, so -4 = -6 + b and b = 2. The equation is y = -3x + 2. Check: -3(2) + 2 = -4.
Exercise
Use point-slope form to find the line with slope 1/2 through (-6, 5). Give the answer in slope-intercept form.
Show answer
y - 5 = (1/2)(x - (-6)) = (1/2)(x + 6) = (1/2)x + 3. Add 5 to both sides: y = (1/2)x + 8. Check: (1/2)(-6) + 8 = 5.
Exercise
A line has slope 0 and passes through (-1, 9). Another line passes through (3, 2) and is vertical. Write both equations and say which one has a slope-intercept form.
Show answer
The first line is y = 9, which is y = 0x + 9, so it has slope-intercept form with m = 0 and b = 9. The second line is x = 3. It has an undefined slope and no slope-intercept form.
Exercise
A student writes the line with slope 4 through (-2, 3) as y - 3 = 4(x - 2) and gets y = 4x - 5. Find the mistake and give the correct equation.
Show answer
The student used x1 = 2 instead of x1 = -2. The correct point-slope form is y - 3 = 4(x + 2), which gives y - 3 = 4x + 8 and y = 4x + 11. Check: 4(-2) + 11 = 3.