Algebra

Straight Line Graph Calculator (y = mx + c)

Enter two points to find the gradient and the equation of the straight line through them in the form y = mx + c. You also get the midpoint, the distance between the points and the perpendicular gradient, with full working.

Point 1 (x₁, y₁)
Point 2 (x₂, y₂)

Line through both points

Equation

y = 3x − 1

Gradient

3

Midpoint

(2, 5)

Distance

2√10 ≈ 6.32

How it works

  1. Find the gradient

    m=y2−y1x2−x1=8−23−1=62=3m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{8 - 2}{3 - 1} = \frac{6}{2} = 3

    Gradient = change in y ÷ change in x = 6 ÷ 2 = 3.

    Result:m = 3
  2. Find the y-intercept

    2=3×1+c  ⟹  c=−12 = 3 \times 1 + c \implies c = -1

    Substitute the point (1, 2) into y = mx + c and solve for c.

    Result:c = −1
  3. Write the equation

    y=3x−1y = 3x - 1

    Put m = 3 and c = −1 into y = mx + c.

    Result:y = 3x − 1
  4. Perpendicular gradient

    −13=−13-\frac{1}{3} = -\frac{1}{3}

    Perpendicular lines have gradients that multiply to −1. The perpendicular gradient is −1/3.

  5. Find the midpoint

    (1+32,2+82)=(2,5)\left(\frac{1 + 3}{2}, \frac{2 + 8}{2}\right) = (2, 5)

    Add the x-coordinates and halve, then do the same for y. Midpoint of (1, 2) and (3, 8) is (2, 5).

    Result:(2, 5)
  6. Find the distance

    d=22+62=40=210≈6.32d = \sqrt{2^2 + 6^2} = \sqrt{40} = 2\sqrt{10} \approx 6.32

    Use Pythagoras on the change in x (2) and the change in y (6).

    Result:2√10 ≈ 6.32

Equation of a straight line

y=mx+cm=y2−y1x2−x1y = mx + c \qquad m = \frac{y_2 - y_1}{x_2 - x_1}
mmGradient — how steep the line is (change in y ÷ change in x)
ccy-intercept — where the line crosses the y-axis
(x₁, y₁), (x₂, y₂)Any two points on the line

Example substitution

(1,2),(3,8):  m=8−23−1=3,  2=3(1)+c⇒c=−1⇒y=3x−1(1, 2), (3, 8): \; m = \frac{8 - 2}{3 - 1} = 3, \; 2 = 3(1) + c \Rightarrow c = -1 \Rightarrow y = 3x - 1

Find the gradient, substitute one point to find c, then write y = mx + c.

Worked examples

Find the equation of the line through (2, 3) and (6, 11)

  1. 1
    Gradient: (11 − 3) ÷ (6 − 2) = 8 ÷ 4 = 2
  2. 2
    Substitute (2, 3): 3 = 2 × 2 + c, so c = −1
Answer: y = 2x − 1

Find the equation of the line through (−1, 4) and (3, −4)

  1. 1
    Gradient: (−4 − 4) ÷ (3 − (−1)) = −8 ÷ 4 = −2
  2. 2
    Substitute (−1, 4): 4 = −2 × (−1) + c, so c = 2
Answer: y = −2x + 2

Find the distance between (1, 1) and (4, 5)

  1. 1
    Change in x and y: 3 and 4
  2. 2
    Pythagoras: √(3² + 4²) = √25
Answer: 5 units

Frequently asked questions

How do you find the gradient between two points?+

Gradient = change in y ÷ change in x = (y₂ − y₁)/(x₂ − x₁). From (1, 2) to (3, 8): (8 − 2)/(3 − 1) = 6/2 = 3.

How do you find the equation of a line from two points?+

Find the gradient m, then substitute one point into y = mx + c to find c. For (1, 2) and (3, 8): m = 3, and 2 = 3 × 1 + c gives c = −1, so the line is y = 3x − 1.

How do you find the midpoint of two points?+

Average the coordinates: ((x₁ + x₂)/2, (y₁ + y₂)/2). The midpoint of (1, 2) and (3, 8) is (2, 5).

How do you find the distance between two points?+

Use Pythagoras: d = √((x₂ − x₁)² + (y₂ − y₁)²). From (1, 2) to (3, 8): √(2² + 6²) = √40 = 2√10 ≈ 6.32.

What is the gradient of a perpendicular line?+

Perpendicular gradients multiply to −1, so flip the fraction and change the sign. A line with gradient 3 has a perpendicular gradient of −1/3.

Related calculators