Processing math: 100%

Two Points: Find Slope and Intercept.

Given two points, p1=(x1,y1) p2=(x2,y2) For the line passing through these two points, find the:
Fig 1. Two points. Point 1: (1, 2) and Point2: (5, 4).
Notes and Code Outcome

Slope

The slope of the line is the change in y divided by the change in x: slope=ΔyΔx
For two points, the change in y and change in x are: Δy=y2y1 Δx=x2x1
The output of your program should be something like:
The slope is: 0.5

Intercept

Finding the intercept requires a little algebra. Since the general equation for a straight line is: y=mx+b where: m=slope b=intercept so to find the intercept we solve this equation for b: ymx=b therefore, b=ymx since we already calculated the slope (m), and we know the x and y values of at least one point, we can substitute in the values: x=x1 y=y1 to get: b=y1mx1
The output of your program should be something like:
The slope is: 0.5
The intercept is: 1.5
Exercise: Draw a graph showing the two points and the line between them, then extend the line to the boundaries of your graph.