Rate of Change Calculator Graph

Rate of Change Calculator

This calculator helps you determine the rate of change between two points on a graph. The rate of change, also known as the slope, represents how much the dependent variable (usually y) changes for each unit change in the independent variable (usually x). The formula for the rate of change between two points (x1, y1) and (x2, y2) is:

Rate of Change = (y2 – y1) / (x2 – x1)

function calculateRateOfChange() { 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 resultDiv = document.getElementById("result"); resultDiv.innerHTML = ""; // Clear previous results if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) { resultDiv.innerHTML = "Please enter valid numbers for all coordinates."; return; } if (x2 – x1 === 0) { resultDiv.innerHTML = "The rate of change is undefined (vertical line)."; return; } var rateOfChange = (y2 – y1) / (x2 – x1); resultDiv.innerHTML = "The Rate of Change is: " + rateOfChange.toFixed(4); } .calculator-container { font-family: sans-serif; max-width: 500px; margin: 20px auto; padding: 20px; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } .calculator-container h2 { text-align: center; margin-bottom: 20px; color: #333; } .calculator-container p { margin-bottom: 15px; line-height: 1.5; color: #555; } .calculator-container p strong { color: #333; } .input-section { margin-bottom: 15px; display: flex; align-items: center; } .input-section label { display: inline-block; width: 50px; margin-right: 10px; font-weight: bold; color: #444; } .input-section input[type="number"] { flex-grow: 1; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; /* Include padding and border in the element's total width and height */ } .calculator-container button { display: block; width: 100%; padding: 12px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } .calculator-container button:hover { background-color: #0056b3; } .result-section { margin-top: 20px; padding: 15px; background-color: #e9ecef; border: 1px solid #ced4da; border-radius: 4px; text-align: center; font-size: 18px; color: #007bff; font-weight: bold; }

Leave a Comment