Find the Linear Function f(x)=mx+b from Two Points

Find the Linear Function f(x)=mx+b from Two Points

Growing AI Skill PRO

Enter Calculation

Formula

f(x)=mx+bwhere{m=y2−y1x2−x1b=y1−m·x1\begin{gathered} f(x) = mx + b \\[1.5em] \text{where}\quad \left\{ \begin{aligned} m &= \frac{{{\text{y}_2}} - {{\text{y}_1}}}{{{\text{x}_2}} - {{\text{x}_1}}} \\[0.5em] b &= {{\text{y}_1}} - m \cdot {{\text{x}_1}} \end{aligned} \right. \end{gathered}
Usage stats

Advertisement

Results

Linear Function
f(x) = 2x + 0
slope-intercept form
Slope (m) 2
Y-intercept (b) 0

Report an error on this page

What This Calculator Does

Given any two distinct points on a line, this tool finds the unique linear function \(f(x) = mx + b\) that passes through both of them. It returns the slope \(m\) and the y-intercept \(b\) so you can write the full equation of the line.

How to Use It

Enter the coordinates of your first point as \(x_1\) and \(y_1\), then your second point as \(x_2\) and \(y_2\). Click calculate and the tool reports the slope and intercept, and assembles them into \(f(x) = mx + b\). If both points have the same x-value, the line is vertical and cannot be expressed in slope-intercept form, so the calculator tells you so.

The Formula Explained

The slope measures how much y changes per unit change in x: $$m = \frac{y_2 - y_1}{x_2 - x_1}$$ Once you know the slope, the y-intercept follows by substituting one point into \(y = mx + b\) and solving for \(b\): $$b = y_1 - m \cdot x_1$$ The result is the equation of the unique straight line through both points.

Advertisement
Line on coordinate axes through two points showing slope rise over run and y-intercept
The slope \(m\) is rise over run between the two points; \(b\) is where the line crosses the y-axis.

Worked Example

For the points (1, 2) and (3, 6): the slope is $$m = \frac{6 - 2}{3 - 1} = \frac{4}{2} = 2$$ The intercept is $$b = 2 - 2 \times 1 = 0$$ So the line is \(f(x) = 2x + 0\), i.e. \(f(x) = 2x\).

Advertisement
Two specific points connected by a line with slope and intercept highlighted
A worked example: two known points determine a single line \(f(x)=mx+b\).

More Worked Examples

Each example uses the same three steps: find the slope \(m\), find the intercept \(b\), then check the result by putting the second point back into \(f(x)\).

Example 1: Negative slope with a nonzero intercept

Points: \((x_1, y_1) = (-2, 7)\) and \((x_2, y_2) = (4, -5)\).

  1. Slope: $$m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{-5 - 7}{4 - (-2)} = \frac{-12}{6} = -2$$ The slope is -2.
  2. Intercept: $$b = y_1 - m \cdot x_1 = 7 - (-2)(-2) = 7 - 4 = 3$$
  3. Function: \(f(x) = -2x + 3\)
  4. Check with the second point: \(f(4) = -2 \cdot 4 + 3 = -8 + 3 = -5\). This equals \(y_2 = -5\), so the result is correct.

Example 2: Fractional slope

Points: \((x_1, y_1) = (1, 4)\) and \((x_2, y_2) = (5, 6)\).

  1. Slope: $$m = \frac{6 - 4}{5 - 1} = \frac{2}{4} = \frac{1}{2} = 0.5$$
  2. Intercept: $$b = 4 - 0.5 \cdot 1 = 4 - 0.5 = 3.5$$ The y-intercept is 3.5.
  3. Function: \(f(x) = 0.5x + 3.5\), which can also be written \(f(x) = \tfrac{1}{2}x + \tfrac{7}{2}\).
  4. Check with the second point: \(f(5) = 0.5 \cdot 5 + 3.5 = 2.5 + 3.5 = 6\). This equals \(y_2 = 6\).

Example 3: Horizontal line

Points: \((x_1, y_1) = (-1, 5)\) and \((x_2, y_2) = (3, 5)\).

  1. Slope: $$m = \frac{5 - 5}{3 - (-1)} = \frac{0}{4} = 0$$
  2. Intercept: $$b = 5 - 0 \cdot (-1) = 5$$
  3. Function: \(f(x) = 0 \cdot x + 5\), which is just \(f(x) = 5\).
  4. Check with the second point: \(f(3) = 0 \cdot 3 + 5 = 5\). This equals \(y_2 = 5\).

Note: if the two points have the same x-value (\(x_1 = x_2\)), the denominator of the slope is zero. That line is vertical, \(x = x_1\), and it cannot be written as \(f(x) = mx + b\).

FAQ

What if the slope is zero? Then both points have the same y-value and the line is horizontal: \(f(x) = b\), a constant.

What if the two x-values are equal? The line is vertical (\(x = \text{constant}\)). It has undefined slope and cannot be written as \(f(x) = mx + b\).

Can the inputs be negative or decimals? Yes. The slope and intercept formulas work for any real coordinates, positive, negative, or fractional.

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators