randRange(-9, 9) randRange(-9, 9) randRange(-9, 9) randRange(-9, 9) (Y1 - Y2) / (X1 - X2) Y1 - M * X1 randRange( 1, 3 )

The equation of the line through the points (X1, Y1) and (X2, Y2) is written in the form y = mx + b.

What are the values of the slope m and the y-intercept b?

graphInit({ range: 10, scale: 20, tickStep: 1, labelStep: 1, unityLabels: false, labelFormat: function( s ) { return "\\small{" + s + "}"; }, axisArrows: "<->" }); line( [X1 - 19, Y1 - 19 * M], [X2 + 19, Y2 + 19 * M], { stroke: "#28ae7b" } ); style({ fill: "#000", stroke: "none" }); circle( [X1, Y1], 3/20 ); circle( [X2, Y2], 3/20 );

m = M

b = B

Let's take a look at the graph:

graphInit({ range: 10, scale: 20, tickStep: 1, labelStep: 1, unityLabels: false, labelFormat: function( s ) { return "\\small{" + s + "}"; }, axisArrows: "<->" }); line( [X1 - 19, Y1 - 19 * M], [X2 + 19, Y2 + 19 * M], { stroke: "#28ae7b" } ); style({ fill: "#000", stroke: "none" }); circle( [X1, Y1], 3/20 ); circle( [X2, Y2], 3/20 );

The equation for the slope is m = \dfrac{y_2 - y_1}{x_2 - x_1}.

Substitute both points.

m = \displaystyle \frac{Y2 - negParens(Y1)}{X2 - negParens(X1)} = fractionSimplification( Y2 - Y1, X2 - X1 ).

Writing the equation of the line, we have y = ( M == -1 ? "-" : ( M == 1 ? "" : fractionReduce( Y2 - Y1, X2 - X1 ))) x + b (the value of m is equal to M).

To find b, we can substitute in either of the two points into the above equation. Let's go through both cases:

Using the first point (X1, Y1), substitute y = Y1 and x = X1:

Y1 = (fractionReduce( Y2 - Y1, X2 - X1 ))(X1) + b.

b = Y1 - fractionReduce( X1 * ( Y2 - Y1 ), X2 - X1 ) = fractionReduce( Y1 * (X2 - X1) - X1 * ( Y2 - Y1 ), X2 - X1 )

Using the second point (X2, Y2), substitute y = Y2 and x = X2:

Y2 = (fractionReduce( Y2 - Y1, X2 - X1 ))(X2) + b.

b = Y2 - fractionReduce( X2 * ( Y2 - Y1 ), X2 - X1 ) = fractionReduce( Y2 * (X2 - X1) - X2 * ( Y2 - Y1 ), X2 - X1 )

In both cases, the equation of the line is y = ( M == -1 ? "-" : ( M == 1 ? "" : fractionReduce( Y2 - Y1, X2 - X1 ))) x + fractionReduce( Y1 * (X2 - X1) - X1 * ( Y2 - Y1 ), X2 - X1 ) (the value of m is equal to M).