Linear Function Calculator (Find y = mx + b from Two Points or a Slope and a Point, Rate of Change and Intercepts)
Choose a mode and enter the coordinates of two points (or the slope and the coordinates of one point). If you also enter an x, the value of y for that x is calculated too.
Table of Contents
-
What you can do on this page
-
What is this calculation used for?
-
How to Use
-
Formulas and graphs
-
Symbols and terms
-
Good to know before you start
-
How to calculate it in Excel
-
How to calculate it in Google Sheets
-
How to calculate it in Python
-
How to write it in LaTeX and other math languages (copy and paste)
-
How to have ChatGPT do the calculation
-
DataChef Features
-
Related Features
-
NumberChef Calculators List
What you can do on this page
- Find the equation \(y = mx + b\) of the line through two points \((x_1,\ y_1)\) and \((x_2,\ y_2)\) on the spot, just by entering the coordinates
- You can also choose a mode that finds the equation from the slope \(m\) and one point on the line
- The slope (rate of change) is shown with the steps of \(m = \dfrac{\Delta y}{\Delta x}\). Answers are shown as fractions in lowest terms (exact values)
- It also finds where the line crosses the x-axis and the y-axis and the value of \(y\) for an \(x\) you choose, and draws a graph of the line
- If the two points have the same x-coordinate, so the line is not a linear function, it tells you that the line is the vertical line "x = constant" and explains why
- A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are all on this page
What is this calculation used for?
A price made of "a base fee plus a charge for each unit you use" is exactly the linear function \(y = mx + b\): the y-intercept \(b\) is the base fee and the slope \(m\) is the price per unit. For example, a taxi that charges $3.50 to start plus $2.50 per mile costs \(y = 2.5x + 3.5\), so a 4-mile ride costs \(2.5 \times 4 + 3.5 = 13.50\) dollars.
Working out the unit price and the base fee from two monthly bills (two points of usage and amount) is exactly "finding the equation from two points".
A spring stretches in proportion to the weight hung on it (Hooke's law), so the total length of the spring, "natural length + stretch", is a linear function. For example, a spring with a natural length of 10 cm that stretches 2 cm for each weight has length \(y = 2x + 10\) (\(x\) is the number of weights).
If you fix the equation from two measurements in an experiment (two points), you can predict the length for weights you have not tried yet. It is a classic example that links middle school science and math.
As a rough average, air gets about 3.5°F cooler for every 1,000 ft you climb (this is called the lapse rate). If you know the temperature at the bottom, a linear function gives a rough estimate of the temperature at the top. For example, if it is 77°F at the trailhead, the temperature at \(x\) thousand feet higher is about \(y = 77 - 3.5x\), so at a summit 6,000 ft higher it is about 56°F.
The real temperature also depends on the weather and humidity, so this is not an exact formula, but it is a practical approximation for deciding what to wear on a hike.
Business costs often take the form "fixed costs such as rent + a variable cost for each item made", which is also a linear function: the y-intercept is the fixed cost and the slope is the variable cost per item.
Comparing the cost line with the sales line shows "how many you need to sell to make a profit" (the break-even point). It is a widely used first step in a business plan.
Fahrenheit (°F), used in the US, and Celsius (°C), used in most other countries, are related exactly by the linear function \(F = 1.8C + 32\). With slope 1.8 and y-intercept 32, it is a familiar example of an exactly linear relationship.
For example, 20°C is \(1.8 \times 20 + 32 = 68\) °F. You can use this formula directly to read a weather forecast abroad or an oven temperature in a recipe from another country.
Formulas and graphs
Symbols and terms
Symbols
| \(y = mx + b\) | y equals m x plus b | The slope-intercept form of a linear function: \(m\) is the slope and \(b\) is the y-intercept. This is the standard form in US schools. (Some countries write it \(y = ax + b\).) |
| \(m\) | m | The slope (rate of change): how much y increases each time x increases by 1. Nobody knows for sure why the letter m is used for slope. |
| \(b\) | b | The y-intercept: the value of y when x = 0, which is the height where the graph crosses the y-axis. |
| \(x_1,\ y_1\) | x sub 1, y sub 1 | The coordinates of point 1. The small number at the lower right is called a subscript; it is a label for "which point" (it is not multiplication or an exponent). |
| \(\Delta\) | delta | The capital Greek letter delta, the Greek D, as in "difference". It stands for "change". \(\Delta x\) is the change in x and \(\Delta y\) is the change in y. |
| \(\left(-\dfrac{b}{m},\ 0\right)\) | negative b over m, zero | The point where the line crosses the x-axis. Its y-coordinate is 0, and its x-coordinate is \(-\dfrac{b}{m}\), the solution of the equation \(mx + b = 0\). |
| \((0,\ b)\) | zero, b | The point where the line crosses the y-axis. Its x-coordinate is 0, and its y-coordinate is the y-intercept \(b\) itself. |
Terms
| linear function | A function of the form \(y = mx + b\). Its graph is a straight line. The word "linear" tells you that x appears only to the first power. Taught in Grade 8. |
| function | A rule that gives back exactly one number for each number you put in. Think of it as a machine: put in \(x\) and out comes \(y\). For example, put 3 into the machine \(y = 2x + 1\) and 7 comes out. |
| slope | A number that tells "how much the line goes up or down for every 1 it goes across" (rise over run). A positive slope rises from left to right, a negative slope falls, and a slope of 0 gives a horizontal line. |
| rate of change | The change in y divided by the change in x, \(\dfrac{\Delta y}{\Delta x}\). For a linear function it is the same wherever you measure it, and it equals the slope \(m\). |
| y-intercept | The y-coordinate of the point where the graph crosses the y-axis (the value of y when x = 0). In the linear function \(y = mx + b\), it is \(b\). (The x-intercept is where the graph crosses the x-axis.) |
| direct variation | A relationship of the form \(y = kx\) (a proportional relationship). When x doubles or triples, y doubles or triples too. It is the special linear function whose y-intercept \(b\) is 0 (its line passes through the origin). Taught in Grade 7. |
| coordinates | A pair of numbers \((x,\ y)\) that gives the position of a point. The horizontal position is the x-coordinate and the vertical position is the y-coordinate. |
| coordinate plane | A plane made by crossing a horizontal number line (the x-axis) and a vertical number line (the y-axis) at a right angle. It is the grid you draw graphs on. |
| origin | The point \((0,\ 0)\) where the x-axis and the y-axis cross. It is written \(O\), from "origin". |
| crossing point | The point where two lines cross. On this page, you find the points where a line crosses the x-axis and the y-axis. |
| change in y | How much a value increased, found as "after − before" (the change in x is found the same way). If the value went down, the change is negative. |
| constant | A fixed number that does not change. In an equation such as "x = 2", the 2 is a constant, and the equation stands for the vertical line whose x-coordinate is always 2. |
| constant function | A function whose y-value is always the same, whatever x is. Its equation has the form \(y = b\), and its graph is a horizontal line parallel to the x-axis. It is \(y = mx + b\) with \(m = 0\); some textbooks count it as a linear function and some do not. |
Good to know before you start
Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
If you get stuck, going back over these topics is the quickest way forward.
| Positive and negative numbers (Grades 6–7) |
|
| The coordinate plane (Grades 5–6) |
|
| Proportional relationships (Grade 7) |
|
| Expressions and equations (Grades 6–8) |
|
| Working with fractions (Grades 5–7) |
|
How to calculate it in Excel
| Point 1 x-coordinate x1 | 1 |
| Point 1 y-coordinate y1 | 3 |
| Point 2 x-coordinate x2 | 4 |
| Point 2 y-coordinate y2 | 9 |
| Slope m (rate of change) | =(B4-B2)/(B3-B1) |
| y-intercept b | =B2-B5*B1 |
| x-intercept (x where it crosses the x-axis) | =-B6/B5 |
| Slope m | 2 |
| x-coordinate of the point x1 | 3 |
| y-coordinate of the point y1 | 7 |
| y-intercept b | =B3-B1*B2 |
| x to find y for | 5 |
| Value of y for that x | =B1*B5+B4 |
| Slope m | 2 |
| y-intercept b | 1 |
| x-intercept (x where it crosses the x-axis) | =-B2/B1 |
| y where it crosses the y-axis | =B2 |
The first table finds the equation from the two points (1, 3) and (4, 9): the slope m is 2, the y-intercept b is 1 (the equation of the line is y = 2x + 1), and the x-intercept is −0.5. "/" is division and "*" is multiplication.
The second table works from the slope 2 and the point (3, 7): the y-intercept b is 1, and y is 11 when x = 5.
The third table finds only where the line crosses the axes, from its equation (slope and y-intercept). If the two points have the same x-coordinate, the divisor is 0 and an error (#DIV/0!) appears. This matches the fact that the slope is undefined (the line is not a linear function).
How to calculate it in Google Sheets
| Point 1 x-coordinate x1 | 1 |
| Point 1 y-coordinate y1 | 3 |
| Point 2 x-coordinate x2 | 4 |
| Point 2 y-coordinate y2 | 9 |
| Slope m (rate of change) | =(B4-B2)/(B3-B1) |
| y-intercept b | =B2-B5*B1 |
| x-intercept (x where it crosses the x-axis) | =-B6/B5 |
| Slope m | 2 |
| x-coordinate of the point x1 | 3 |
| y-coordinate of the point y1 | 7 |
| y-intercept b | =B3-B1*B2 |
| x to find y for | 5 |
| Value of y for that x | =B1*B5+B4 |
| Slope m | 2 |
| y-intercept b | 1 |
| x-intercept (x where it crosses the x-axis) | =-B2/B1 |
| y where it crosses the y-axis | =B2 |
How to calculate it in Python
from fractions import Fraction
# Coordinates of the two points (a fraction such as 3/4 can be written Fraction(3, 4))
x1, y1 = Fraction(1), Fraction(3)
x2, y2 = Fraction(4), Fraction(9)
slope = (y2 - y1) / (x2 - x1) # slope m (rate of change) = Δy ÷ Δx
intercept = y1 - slope * x1 # y-intercept b = y1 − m×x1
print(f"Slope m = {slope}")
print(f"y-intercept b = {intercept}")
print(f"Equation of the line: y = {slope}x + {intercept}")
if slope != 0:
print(f"Crosses the x-axis at: ({-intercept / slope}, 0)")
print(f"Crosses the y-axis at: (0, {intercept})")
x_value = Fraction(5) # the x to find y for
print(f"When x = {x_value}, y = {slope * x_value + intercept}")
How to write it in LaTeX and other math languages (copy and paste)
y = mx + b
y = mx + b
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>y</mi>
<mo>=</mo>
<mi>m</mi><mi>x</mi>
<mo>+</mo>
<mi>b</mi>
</mrow>
</math>
y = m x + b
y == m x + b
y := m*x + b;
y = m*x + b;
y = mx + b
m = (y₂ − y₁) ÷ (x₂ − x₁)
m = \frac{y_2 - y_1}{x_2 - x_1}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>m</mi>
<mo>=</mo>
<mfrac>
<mrow><msub><mi>y</mi><mn>2</mn></msub><mo>−</mo><msub><mi>y</mi><mn>1</mn></msub></mrow>
<mrow><msub><mi>x</mi><mn>2</mn></msub><mo>−</mo><msub><mi>x</mi><mn>1</mn></msub></mrow>
</mfrac>
</mrow>
</math>
m = (y_2 - y_1)/(x_2 - x_1)
(y2 - y1)/(x2 - x1)
m := (y2 - y1)/(x2 - x1);
m = (y2 - y1)/(x2 - x1);
m = (y_2 - y_1)/(x_2 - x_1)
b = y₁ − mx₁
b = y_1 - m x_1
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>b</mi>
<mo>=</mo>
<msub><mi>y</mi><mn>1</mn></msub>
<mo>−</mo>
<mi>m</mi>
<msub><mi>x</mi><mn>1</mn></msub>
</mrow>
</math>
b = y_1 - m x_1
y1 - m x1
b := y1 - m*x1;
b = y1 - m*x1;
b = y_1 - m x_1
x = −b ÷ m
x = -\frac{b}{m}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>x</mi>
<mo>=</mo>
<mo>−</mo>
<mfrac><mi>b</mi><mi>m</mi></mfrac>
</mrow>
</math>
x = -b/m
-b/m
x := -b/m;
x = -b/m;
x = −b/m
How to have ChatGPT do the calculation
You are a math calculation assistant for linear functions. Do the following calculation by actually running Python code, and base your answer only on the numbers from the execution result (do not answer by mental math or guessing). Find the equation y = mx + b of the line through the two points (1, 3) and (4, 9). Show each of the following: 1. The slope m (rate of change), with the steps of Δy/Δx 2. The y-intercept b 3. The equation of the line y = mx + b 4. The coordinates of the points where the line crosses the x-axis and the y-axis 5. The value of y when x = 5 In Python, use the fractions module from the standard library to calculate exactly, and show the formulas you used and the numbers from the execution result. If an answer is a fraction, give it in lowest terms.
How to Use
-
1Enter your numbersType the numbers you want to calculate with into the input fields
-
2CalculatePress the "Calculate" button
-
3Check the resultThe result appears on the spot. The same page also explains the idea behind the calculation and the formula
DataChef Features
No technical knowledge required.
Intuitive and user-friendly operation.
Can be used without registering personal information.
Automatic file deletion by clicking "download".
and rapid file conversion.
No attribution required.
No need to contact us for commercial use permission.
