Sub topic 7
Slope-intercept form: y = mx + b
What this chapter covers
This chapter assumes you can already compute slope from two points, read the sign of a slope, and locate a y-intercept on a graph. You should also be comfortable with signed numbers, fractions, and solving two-step equations.
Here you will combine those pieces into one equation, y = mx + b. You will learn what each symbol means, how to read it, how to check it, and where it fails.
The form and its parts
Slope-intercept form writes a line as:
y = mx + b
xis the input. It is the horizontal coordinate.yis the output. It is the vertical coordinate.mis the slope. It is the change inyfor each increase of 1 inx.bis the y-intercept. It is the value ofywhenx = 0, so the line crosses the y-axis at the point(0, b).
The form is useful because m and b are visible directly. You do not need to calculate anything to read them.
| Equation | m | b | Reading |
|---|---|---|---|
| y = 2x + 1 | 2 | 1 | Rises 2 per 1 step right, crosses at (0, 1) |
| y = -3x + 4 | -3 | 4 | Falls 3 per 1 step right, crosses at (0, 4) |
| y = x/2 - 5 | 1/2 | -5 | Rises 1 per 2 steps right, crosses at (0, -5) |
| y = 7 | 0 | 7 | Horizontal line at height 7 |
| y = -x | -1 | 0 | Falls 1 per 1 step right, passes through the origin |
Why the form works
Take any two points on the line y = mx + b. Call them (x1, y1) and (x2, y2). Then:
y1 = m*x1 + by2 = m*x2 + b
Subtract the first from the second. The b terms cancel:
y2 - y1 = m(x2 - x1)
Divide both sides by x2 - x1, which is nonzero for two points with different x-values:
(y2 - y1) / (x2 - x1) = m
This is the slope formula. So the number m in the equation is the slope you would compute from any two points on the line. It does not depend on which two points you pick.
Setting x = 0 gives y = m*0 + b = b. That is why b is the y-intercept.
Reading a line from its equation
Follow these steps for an equation already in slope-intercept form.
- Find the coefficient of
x. That ism. Keep its sign. - Find the constant term. That is
b. Keep its sign. - Classify the direction from the sign of
m: positive rises, negative falls, zero is horizontal.
For y = -3x + 4:
m = -3, so the line falls.b = 4, so the line crosses the y-axis at(0, 4).
If the equation is written as y = 4 - 3x, the terms are in a different order but the meaning is the same. The slope is still the coefficient of x, which is -3, and b is still 4.
Evaluating the equation
The equation is also a rule for producing points. Substitute an x and compute y.
For y = 2x + 1:
| x | Calculation | y | Point |
|---|---|---|---|
| -2 | 2(-2) + 1 | -3 | (-2, -3) |
| 0 | 2(0) + 1 | 1 | (0, 1) |
| 1 | 2(1) + 1 | 3 | (1, 3) |
| 3 | 2(3) + 1 | 7 | (3, 7) |
Each time x rises by 1, y rises by 2. That is the slope showing up in the table. A table whose y-values change by a constant amount for equal steps in x describes a line.
The same check works in code:
def y_value(m, b, x):
return m * x + b
m, b = 2, 1
for x in [-2, 0, 1, 3]:
print(f"x = {x:>2} y = {y_value(m, b, x)}")The output is -3, 1, 3, and 7, matching the table.
Testing whether a point is on the line
A point (x0, y0) is on the line y = mx + b exactly when substituting x0 gives y0.
Test (4, 9) and (4, 10) against y = 2x + 1:
- At
x = 4:2(4) + 1 = 9. (4, 9)is on the line.(4, 10)is not on the line, because the line has height 9 atx = 4.
A line has exactly one y for each x. This is why slope-intercept form describes a function.
Building the equation from m and b
Going the other way is direct. If you know the slope and the y-intercept, write them into the form.
A line has slope -1/2 and y-intercept 3. The equation is:
y = -(1/2)x + 3
You can also write this as y = -x/2 + 3. The two forms are the same.
When you know the slope and a point that is not the y-intercept, you must first find b. Substitute the point and solve. For slope 3 through (2, 5):
- Start with
y = 3x + b. - Substitute
x = 2andy = 5:5 = 3(2) + b. - Simplify:
5 = 6 + b. - Solve:
b = -1. - Write the result:
y = 3x - 1.
Check by substituting the point back: 3(2) - 1 = 5. It matches.
The same idea computes the intercept from two points. Find m with the slope formula, then solve for b using either point:
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.0The points (1, 3) and (3, 7) give m = 4 / 2 = 2. Then b = 3 - 2(1) = 1. The line is y = 2x + 1.
How m and b move the line
You can build intuition by changing one value at a time.
- Changing
bshifts the whole line up or down. The slope stays the same, so the shifted lines are parallel. - Changing
mrotates the line around the y-intercept(0, b). The intercept stays fixed. - A larger
|m|gives a steeper line. A smaller|m|gives a flatter line. - Changing the sign of
mmirrors the steepness.y = 2x + 1rises, andy = -2x + 1falls at the same steepness through the same intercept.
Edge cases
Horizontal lines
When m = 0, the equation becomes y = b. Every point has the same y. The line is horizontal, and the form still applies.
Vertical lines
A vertical line has the equation x = k for some constant k. Every point has the same x, so the run is 0 and the slope is undefined. No value of m fits. Slope-intercept form cannot describe it, and x = k cannot be rewritten as y = mx + b.
Lines through the origin
When b = 0, the equation is y = mx. The line passes through (0, 0). Here y is proportional to x.
Hidden coefficients of 1
y = x + 4 has m = 1, because x means 1x. y = -x + 4 has m = -1. Writing the coefficient out when you are unsure prevents mistakes.
Equations not yet solved for y
The form requires y alone on the left with coefficient 1. These equations are not yet in slope-intercept form:
2y = 6x + 4x + y = 53x - 2y = 8
Rearrange first. For 2y = 6x + 4, divide every term by 2 to get y = 3x + 2. Dividing only some terms is a common error. Reading m = 6 and b = 4 straight from 2y = 6x + 4 is wrong.
For 3x - 2y = 8:
- Subtract
3x:-2y = -3x + 8. - Divide each term by
-2:y = (3/2)x - 4.
The slope is 3/2 and the intercept is -4. Dividing by a negative flips the sign of every term. The next chapters cover standard-form conversion in more detail, and this code shows the pattern:
from fractions import Fraction
def standard_to_slope_intercept(A, B, C):
if B == 0:
raise ValueError("B = 0 gives a vertical line")
return Fraction(-A, B), Fraction(C, B)
m, b = standard_to_slope_intercept(3, -2, 8)
print(m, b) # 3/2 -4Common errors
| Error | Example | Correction |
|---|---|---|
| Using the wrong sign for b | y = 3x - 5 read as b = 5 | b = -5, because the subtraction belongs to the constant |
| Swapping m and b | y = 4x + 7 read as m = 7 | m is the coefficient of x, so m = 4 |
| Reading from an unsolved equation | 2y = 4x + 6 read as m = 4 | Divide all terms by 2 first: m = 2, b = 3 |
| Plotting the intercept on the x-axis | y = x + 3 plotted at (3, 0) | The intercept is (0, 3) |
| Dropping the sign in rise over run | m = -2/3 moved up 2, right 3 | Move down 2 and right 3, or up 2 and left 3 |
| Forcing a vertical line into the form | x = 5 written as y = mx + b | It has no slope-intercept form |
Check your understanding
Exercise
A line has the equation y = -4x + 9. State the slope and the y-intercept. Say whether the line rises or falls, and decide whether the point (2, 1) is on the line.
Show answer
The slope is m = -4 and the y-intercept is b = 9, so the line crosses the y-axis at (0, 9). Because m is negative, the line falls from left to right. At x = 2, y = -4(2) + 9 = 1, so the point (2, 1) is on the line.
Exercise
Write the equation of the line with slope 5 that passes through (3, 2). Give the answer in slope-intercept form.
Show answer
Start with y = 5x + b. Substitute (3, 2): 2 = 5(3) + b, so 2 = 15 + b and b = -13. The equation is y = 5x - 13. Check: 5(3) - 13 = 2.
Exercise
Put 4x + 2y = 10 into slope-intercept form, and then give m and b.
Show answer
Subtract 4x from both sides: 2y = -4x + 10. Divide every term by 2: y = -2x + 5. So m = -2 and b = 5.
Exercise
Why can the line x = 3 not be written as y = mx + b?
Show answer
Every point on x = 3 has the same x-value, so the run between any two points is 0. The slope formula would divide by 0, so the slope is undefined. No number m makes y = mx + b give a vertical line, because that equation gives exactly one y for each x, and x = 3 has many y-values at the single x-value 3.