Linear Calculator

.linear-calc-container { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 20px auto; padding: 25px; border: 1px solid #e1e1e1; border-radius: 12px; background-color: #ffffff; box-shadow: 0 4px 15px rgba(0,0,0,0.05); } .linear-calc-container h2 { color: #2c3e50; text-align: center; margin-bottom: 25px; font-size: 24px; } .calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; } .input-group { display: flex; flex-direction: column; } .input-group label { margin-bottom: 8px; font-weight: 600; color: #34495e; font-size: 14px; } .input-group input { padding: 12px; border: 2px solid #edeff2; border-radius: 6px; font-size: 16px; transition: border-color 0.3s; } .input-group input:focus { border-color: #3498db; outline: none; } .full-width { grid-column: span 2; } .calc-btn { background-color: #3498db; color: white; border: none; padding: 15px; border-radius: 6px; font-size: 18px; font-weight: bold; cursor: pointer; width: 100%; transition: background-color 0.3s; margin-top: 10px; } .calc-btn:hover { background-color: #2980b9; } #linearResult { margin-top: 25px; padding: 20px; background-color: #f8f9fa; border-left: 5px solid #3498db; border-radius: 4px; display: none; } .result-item { margin-bottom: 10px; font-size: 16px; line-height: 1.6; } .result-item strong { color: #2c3e50; } .equation-box { background: #eef2f7; padding: 10px; text-align: center; font-family: "Courier New", Courier, monospace; font-weight: bold; font-size: 20px; margin: 15px 0; border-radius: 4px; } .article-section { margin-top: 40px; line-height: 1.8; color: #444; } .article-section h3 { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 5px; margin-top: 30px; } @media (max-width: 600px) { .calc-grid { grid-template-columns: 1fr; } .full-width { grid-column: span 1; } }

Linear Equation & Slope Calculator

Slope (m):
Y-Intercept (b):

What is a Linear Equation?

A linear equation is an algebraic equation in which each term is either a constant or the product of a constant and a single variable. In a two-dimensional coordinate system, a linear equation represents a straight line. The most common form is the Slope-Intercept Form, expressed as:

y = mx + b

Understanding the Components

  • m (Slope): This represents the steepness of the line. It is calculated as the "rise over run," or the change in Y divided by the change in X.
  • b (Y-Intercept): This is the point where the line crosses the Y-axis (where x = 0).
  • (x, y): Any coordinate point that lies on the line.

How to Calculate the Slope and Intercept

If you have two points, (x₁, y₁) and (x₂, y₂), you can find the characteristics of the line using these steps:

  1. Find the Slope (m): m = (y₂ – y₁) / (x₂ – x₁)
  2. Find the Y-Intercept (b): b = y₁ – (m * x₁)
  3. Assemble the Equation: Plug m and b into the y = mx + b formula.

Practical Example

Suppose you have two points: (1, 2) and (3, 6).

  • Slope: (6 – 2) / (3 – 1) = 4 / 2 = 2
  • Intercept: 2 – (2 * 1) = 0
  • Equation: y = 2x + 0 (or simply y = 2x)

Using this equation, if you wanted to find the value of Y when X is 5, you would calculate: y = 2 * 5 = 10.

function calculateLinear() { var x1 = parseFloat(document.getElementById('x1').value); var y1 = parseFloat(document.getElementById('y1').value); var x2 = parseFloat(document.getElementById('x2').value); var y2 = parseFloat(document.getElementById('y2').value); var targetX = document.getElementById('targetX').value; var resultDiv = document.getElementById('linearResult'); var resSlope = document.getElementById('resSlope'); var resIntercept = document.getElementById('resIntercept'); var resEquation = document.getElementById('resEquation'); var interpRes = document.getElementById('interpolationResult'); if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) { alert('Please enter valid numerical coordinates for both points.'); return; } if (x1 === x2) { resultDiv.style.display = 'block'; resSlope.innerHTML = 'Undefined (Vertical Line)'; resIntercept.innerHTML = 'None (or all points if x=0)'; resEquation.innerHTML = 'x = ' + x1; interpRes.innerHTML = 'Note: This is a vertical line. Y can be any value at x = ' + x1; return; } // Calculate Slope (m) var m = (y2 – y1) / (x2 – x1); // Calculate Y-Intercept (b) var b = y1 – (m * x1); // Format for display var mDisp = +m.toFixed(4); var bDisp = +b.toFixed(4); var sign = bDisp >= 0 ? "+ " : "- "; var bAbs = Math.abs(bDisp); var equationString = "y = " + mDisp + "x " + sign + bAbs; if (bDisp === 0) { equationString = "y = " + mDisp + "x"; } resSlope.innerHTML = mDisp; resIntercept.innerHTML = bDisp; resEquation.innerHTML = equationString; // Handle Interpolation / Extrapolation if (targetX !== "") { var tx = parseFloat(targetX); if (!isNaN(tx)) { var ty = (m * tx) + b; interpRes.innerHTML = "Result: When x = " + tx + ", y = " + (+ty.toFixed(4)) + ""; } else { interpRes.innerHTML = ""; } } else { interpRes.innerHTML = "Enter a target X value above to solve for Y."; } resultDiv.style.display = 'block'; }

Leave a Comment