The average rate of change describes how much a function's output changes, on average, with respect to its input over a given interval. It's essentially the slope of the secant line connecting two points on the function's graph.
Average Rate of Change Calculator
To calculate the average rate of change, we need two points on a function, (x1, y1) and (x2, y2). The formula is:
Average Rate of Change = (y2 – y1) / (x2 – x1)
function calculateAverageRateOfChange() {
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");
if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) {
resultDiv.textContent = "Please enter valid numbers for all points.";
return;
}
if (x2 – x1 === 0) {
resultDiv.textContent = "Error: Division by zero. x1 cannot be equal to x2.";
return;
}
var averageRateOfChange = (y2 – y1) / (x2 – x1);
resultDiv.textContent = "The Average Rate of Change is: " + averageRateOfChange.toFixed(4);
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.input-group input {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
button {
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}