Linear Equation Calculator
Use this calculator to determine the slope, y-intercept, equation, distance, and midpoint between two given points on a Cartesian coordinate system.
Understanding Linear Equations and Their Properties
A linear equation represents a straight line on a graph. It's one of the most fundamental concepts in algebra and geometry, used to model relationships where a change in one quantity results in a proportional change in another.
What is a Linear Equation?
In its most common form, a linear equation is expressed as y = mx + b, where:
y is the dependent variable (output)
x is the independent variable (input)
m is the slope of the line
b is the y-intercept
This equation describes all the points (x, y) that lie on the straight line.
Key Properties Calculated:
-
Slope (m): The slope measures the steepness and direction of a line. It's defined as the "rise over run," or the change in the y-coordinate divided by the change in the x-coordinate between any two distinct points on the line.
Formula: m = (y₂ - y₁) / (x₂ - x₁)
- A positive slope indicates an upward trend (line goes up from left to right).
- A negative slope indicates a downward trend (line goes down from left to right).
- A slope of zero indicates a horizontal line.
- An undefined slope (when x₁ = x₂) indicates a vertical line.
-
Y-intercept (b): The y-intercept is the point where the line crosses the y-axis. At this point, the x-coordinate is always zero (0, b). It represents the value of y when x is zero.
Formula: b = y₁ - m * x₁ (or b = y₂ - m * x₂)
-
Equation of the Line: This is the algebraic expression
y = mx + b that defines the relationship between x and y for all points on the line. For vertical lines, the equation is simply x = c, where 'c' is the constant x-coordinate.
-
Distance Between Two Points: This is the length of the line segment connecting the two given points. It's calculated using the Pythagorean theorem.
Formula: d = √((x₂ - x₁)² + (y₂ - y₁)² )
-
Midpoint: The midpoint is the exact center of the line segment connecting the two given points. It's found by averaging the x-coordinates and averaging the y-coordinates.
Formula: Midpoint = ((x₁ + x₂) / 2, (y₁ + y₂) / 2)
How to Use the Calculator
Simply enter the x and y coordinates for your two points (Point 1 and Point 2) into the respective input fields. Click the "Calculate Linear Properties" button, and the calculator will instantly display the slope, y-intercept, full equation of the line, the distance between the points, and their midpoint.
Example Calculation:
Let's consider two points: Point 1 (2, 3) and Point 2 (8, 15).
- x₁ = 2, y₁ = 3
- x₂ = 8, y₂ = 15
- Slope (m):
m = (15 - 3) / (8 - 2) = 12 / 6 = 2
- Y-intercept (b): Using Point 1:
3 = 2 * 2 + b => 3 = 4 + b => b = -1
- Equation of the Line:
y = 2x - 1
- Distance:
d = √((8 - 2)² + (15 - 3)²) = √(6² + 12²) = √(36 + 144) = √180 ≈ 13.416
- Midpoint:
((2 + 8) / 2, (3 + 15) / 2) = (10 / 2, 18 / 2) = (5, 9)
This calculator automates these calculations, providing quick and accurate results for any pair of points.
.linear-calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 700px;
margin: 20px auto;
padding: 25px;
border: 1px solid #e0e0e0;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
color: #333;
}
.linear-calculator-container h2 {
text-align: center;
color: #2c3e50;
margin-bottom: 20px;
font-size: 1.8em;
}
.linear-calculator-container h3 {
color: #34495e;
margin-top: 30px;
margin-bottom: 15px;
font-size: 1.4em;
}
.linear-calculator-container h4 {
color: #34495e;
margin-top: 20px;
margin-bottom: 10px;
font-size: 1.1em;
}
.linear-calculator-container p {
line-height: 1.6;
margin-bottom: 15px;
}
.calculator-inputs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-bottom: 25px;
padding: 15px;
background-color: #f9f9f9;
border-radius: 8px;
border: 1px solid #eee;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 8px;
font-weight: bold;
color: #555;
font-size: 0.95em;
}
.input-group input[type="number"] {
padding: 10px 12px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1em;
width: calc(100% – 24px); /* Adjust for padding */
box-sizing: border-box;
}
.input-group input[type="number"]:focus {
border-color: #007bff;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
outline: none;
}
.calculator-inputs button {
grid-column: 1 / -1; /* Span across all columns */
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
margin-top: 10px;
}
.calculator-inputs button:hover {
background-color: #0056b3;
transform: translateY(-1px);
}
.calculator-inputs button:active {
background-color: #004085;
transform: translateY(0);
}
.calculator-results {
margin-top: 25px;
padding: 20px;
border: 1px solid #d1e7dd;
border-radius: 8px;
background-color: #eaf7ee;
color: #0f5132;
font-size: 1.1em;
line-height: 1.8;
}
.calculator-results strong {
color: #0a3622;
}
.calculator-results p {
margin-bottom: 8px;
}
.calculator-results p:last-child {
margin-bottom: 0;
}
.calculator-article {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #e0e0e0;
}
.calculator-article ul, .calculator-article ol {
margin-left: 20px;
margin-bottom: 15px;
}
.calculator-article ul li, .calculator-article ol li {
margin-bottom: 8px;
line-height: 1.5;
}
.calculator-article code {
background-color: #e9ecef;
padding: 2px 5px;
border-radius: 4px;
font-family: 'Consolas', 'Monaco', monospace;
color: #c7254e;
}
@media (max-width: 600px) {
.calculator-inputs {
grid-template-columns: 1fr;
}
}
function calculateLinearProperties() {
var x1 = parseFloat(document.getElementById("x1Coordinate").value);
var y1 = parseFloat(document.getElementById("y1Coordinate").value);
var x2 = parseFloat(document.getElementById("x2Coordinate").value);
var y2 = parseFloat(document.getElementById("y2Coordinate").value);
var resultDiv = document.getElementById("result");
var output = "";
if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) {
resultDiv.innerHTML = "Please enter valid numbers for all coordinates.";
return;
}
// Calculate Slope (m)
var slope;
var deltaX = x2 – x1;
var deltaY = y2 – y1;
if (deltaX === 0) {
slope = "undefined (vertical line)";
} else {
slope = deltaY / deltaX;
}
// Calculate Y-intercept (b)
var yIntercept;
if (slope === "undefined (vertical line)") {
yIntercept = "N/A (vertical line)";
} else if (slope === 0) { // Horizontal line
yIntercept = y1;
} else {
yIntercept = y1 – slope * x1;
}
// Determine Equation of the Line
var equation;
if (slope === "undefined (vertical line)") {
equation = "x = " + x1.toFixed(2);
} else if (slope === 0) {
equation = "y = " + y1.toFixed(2);
} else {
var sign = yIntercept >= 0 ? "+" : "-";
equation = "y = " + slope.toFixed(2) + "x " + sign + " " + Math.abs(yIntercept).toFixed(2);
if (yIntercept === 0) {
equation = "y = " + slope.toFixed(2) + "x";
}
}
// Calculate Distance
var distance = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
// Calculate Midpoint
var midpointX = (x1 + x2) / 2;
var midpointY = (y1 + y2) / 2;
output += "
Slope (m): " + (typeof slope === 'number' ? slope.toFixed(2) : slope) + "";
output += "
Y-intercept (b): " + (typeof yIntercept === 'number' ? yIntercept.toFixed(2) : yIntercept) + "";
output += "
Equation of the Line: " + equation + "";
output += "
Distance Between Points: " + distance.toFixed(3) + "";
output += "
Midpoint: (" + midpointX.toFixed(2) + ", " + midpointY.toFixed(2) + ")";
resultDiv.innerHTML = output;
}
// Initial calculation on page load with default values
window.onload = function() {
calculateLinearProperties();
};