Home / Algebra

Equation of a Line (y = mx + c)

Set the slope and intercept, then track how y changes as x moves. Switch to 3D to explore a line with both y and z coordinates.

Parameters


Slope (m)
Y-Int (c)
Slope (mz)
Z-Int (cz)

-10 0 10

Presets

Graph Explorer

Click points & drag arrows

Overview

Read slope and intercept

y = mx + c

The slope m is the rate of change: how much y changes for each unit change in x. A positive slope rises as x increases; a negative slope falls; zero makes a horizontal line. The intercept c is the y-coordinate where the line crosses the y-axis, at (0, c).

For y = 2x + 1, x = 0 gives y = 1, and every increase of 1 in x raises y by 2. In the graph, set Slope (m) to 2 and Y-Int (c) to 1. Changing c to 3 moves every point up by 2; changing m changes how quickly y rises.

Read a Line from Its Equation

In y = mx + c, m gives the change in y for each unit of x; c gives y when x = 0. Change either value in the graph to see its effect.

Build a line from two points

For points (1, 5) and (3, 11), the slope is

m = (11 − 5) / (3 − 1) = 3

Substitute either point into y = mx + c. Using (1, 5), 5 = 3(1) + c, so c = 2. The line is y = 3x + 2; checking the second point gives 11 = 3(3) + 2.

The same line can be written in point-slope form as y - 5 = 3(x - 1), which starts from a known point and slope. Rearranging gives slope-intercept form, y = 3x + 2, or standard form, 3x - y + 2 = 0.

This method fails when the two points have the same x-coordinate: the run is zero, so the slope is undefined. That line is vertical and has the form x = k; it cannot be written as y = mx + c.

Fit a line to measured data

Real measurements rarely land exactly on one line. Ordinary least squares chooses the slope and intercept that minimise the sum of squared vertical residuals. With an intercept, the fitted coefficients are

m = Σ[(x − x̄)(y − ȳ)] / Σ[(x − x̄)²]  c = ȳ − m x̄

For example, fitting the points (1, 2.1), (2, 4.2), (3, 5.8), (4, 8.1), (5, 9.9) gives y = 1.95x + 0.17. In this range, a one-unit increase in x is associated with about a 1.95-unit increase in y. That describes an association; it does not show that x causes y. A straight-line fit can also be misleading when the relationship curves or when it is extrapolated far beyond the measured x-values.

The fitted line passes through (x̄, ȳ). The scikit-learn linear regression lesson shows the same fit in code; the official LinearRegression documentation describes its ordinary least-squares objective.

Connect the line to a classifier

A classifier with two input features can place its decision boundary where w₁x₁ + w₂x₂ + b = 0. When w₂ ≠ 0, rearranging gives x₂ = −(w₁/w₂)x₁ − b/w₂, which is a line: its slope is −w₁/w₂ and its intercept is −b/w₂. This is why a linear model's boundary can be drawn as a line, while its coefficients are not each individually “the slope” or “the intercept.” See the perceptron lesson for the weighted-sum form.

Try this above

  1. Press Horizontal. The slope is zero, so moving x does not change y.
  2. Press Negative. The line falls from left to right; the sign sets direction, while the absolute value sets steepness.
  3. Set Slope (m) to 2 and Y-Int (c) to 1. Move the x control and check that each increase of 1 raises y by 2.
  4. Change only Y-Int (c). The line shifts without changing its slope.
  5. Switch to 3D Space and vary the second slope. The visualiser traces a 3D line whose y and z coordinates each change with x.

Sources

Predict, then reveal

About to run: Slope (m). Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Check yourself

0 of 4

Answer without scrolling back up.

  1. In y = mx + c, what does c control?

  2. A line has slope m = 0. What does it look like?

  3. Why does this one equation matter so much later on?

  4. For y = 3x + 2, what changes if the intercept becomes 4 and the slope stays 3?

Cheat sheet

Equation of a Line (y = mx + c)

Drag slope and intercept and watch y = mx + c respond. See slope-intercept, point-slope and standard form describe the same line.

MATHS · vizlearn.in/maths/equation_of_line.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.