Two Points (x1, y1) and (x2, y2)
Slope (m) and One Point (x1, y1)
Resulting Equation:
Understanding the Slope Intercept Form
The slope intercept form is one of the most common ways to represent a linear equation. It allows mathematicians, students, and engineers to quickly identify the direction of a line and where it crosses the vertical axis.
The Slope Intercept Formula
The standard formula for the slope-intercept form is:
y = mx + b
y: The y-coordinate (dependent variable).
x: The x-coordinate (independent variable).
m: The Slope, representing the steepness (rise over run).
b: The Y-intercept, the point where the line crosses the y-axis.
How to Find the Slope Intercept Form
Method 1: Using Two Points
If you have two points (x₁, y₁) and (x₂, y₂), follow these steps:
Calculate the slope: m = (y₂ – y₁) / (x₂ – x₁)
Use the point-slope formula to find b: b = y₁ – m * x₁
Plug m and b into the equation.
Method 2: Using Slope and One Point
If you already know the slope (m) and one point (x₁, y₁):
Substitute the known values into y = mx + b.
Solve for b: b = y – mx.
Write the final equation.
Real-World Example
Suppose a taxi company charges a flat fee of 5 (the y-intercept) and then 2 per mile (the slope). The equation representing the cost (y) for miles driven (x) would be:
y = 2x + 5
If you drive 10 miles, the calculation is: y = 2(10) + 5 = 25.
function toggleInputs() {
var mode = document.getElementById("calcMode").value;
var p2Inputs = document.getElementById("point2Inputs");
var slopeInput = document.getElementById("slopeInput");
if (mode === "twoPoints") {
p2Inputs.style.display = "grid";
slopeInput.style.display = "none";
} else {
p2Inputs.style.display = "none";
slopeInput.style.display = "grid";
}
}
function calculateSlopeIntercept() {
var mode = document.getElementById("calcMode").value;
var x1 = parseFloat(document.getElementById("x1").value);
var y1 = parseFloat(document.getElementById("y1").value);
var m, b, equation, details;
if (isNaN(x1) || isNaN(y1)) {
alert("Please enter valid coordinates for Point 1.");
return;
}
if (mode === "twoPoints") {
var x2 = parseFloat(document.getElementById("x2").value);
var y2 = parseFloat(document.getElementById("y2").value);
if (isNaN(x2) || isNaN(y2)) {
alert("Please enter valid coordinates for Point 2.");
return;
}
if (x1 === x2) {
if (y1 === y2) {
equation = "Not a line (Point)";
details = "Both points are identical. A line cannot be defined.";
} else {
equation = "x = " + x1;
details = "This is a vertical line. The slope is undefined.";
}
} else {
m = (y2 – y1) / (x2 – x1);
b = y1 – (m * x1);
formatResult(m, b);
details = "Step 1: Calculate slope (m) = (" + y2 + " – " + y1 + ") / (" + x2 + " – " + x1 + ") = " + m.toFixed(4) + "" +
"Step 2: Solve for b using y = mx + b: " + y1 + " = (" + m.toFixed(4) + " * " + x1 + ") + b " +
"Step 3: b = " + b.toFixed(4);
}
} else {
m = parseFloat(document.getElementById("slopeM").value);
if (isNaN(m)) {
alert("Please enter a valid slope.");
return;
}
b = y1 – (m * x1);
formatResult(m, b);
details = "Step 1: Use given slope m = " + m + "" +
"Step 2: Solve for b using y = mx + b: " + y1 + " = (" + m + " * " + x1 + ") + b " +
"Step 3: b = " + b.toFixed(4);
}
function formatResult(mVal, bVal) {
var mStr = "";
var bStr = "";
// Format Slope
if (mVal === 0) {
mStr = "";
} else if (mVal === 1) {
mStr = "x";
} else if (mVal === -1) {
mStr = "-x";
} else {
mStr = parseFloat(mVal.toFixed(4)) + "x";
}
// Format Intercept
if (bVal === 0) {
bStr = (mVal === 0) ? "0" : "";
} else if (bVal > 0) {
bStr = (mVal === 0) ? parseFloat(bVal.toFixed(4)) : " + " + parseFloat(bVal.toFixed(4));
} else {
bStr = (mVal === 0) ? parseFloat(bVal.toFixed(4)) : " – " + Math.abs(parseFloat(bVal.toFixed(4)));
}
equation = "y = " + mStr + bStr;
if (mStr === "" && bStr === "") equation = "y = 0";
}
document.getElementById("finalEquation").innerHTML = equation;
document.getElementById("stepDetails").innerHTML = details;
document.getElementById("slopeResult").style.display = "block";
}