The average rate of change of a function measures how much the function's output changes, on average, for a given change in its input. It's essentially the slope of the secant line connecting two points on the function's graph. To calculate it, you need two points (x1, y1) and (x2, y2). The formula is:
Average Rate of Change = (y2 – y1) / (x2 – x1)
This calculator will help you find the average rate of change given two points.
#averageRateOfChangeCalculator {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
#calculatorTitle {
text-align: center;
margin-bottom: 15px;
color: #333;
}
#calculatorDescription {
margin-bottom: 20px;
line-height: 1.6;
color: #555;
font-size: 0.95em;
}
.input-group {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-group input {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1em;
}
button {
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1em;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 25px;
padding: 15px;
background-color: #e9ecef;
border: 1px solid #dee2e6;
border-radius: 4px;
text-align: center;
font-size: 1.2em;
font-weight: bold;
color: #333;
}
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.innerHTML = "Please enter valid numbers for all inputs.";
return;
}
if (x2 – x1 === 0) {
resultDiv.innerHTML = "Cannot calculate: The change in x (x2 – x1) is zero. This represents a vertical line or undefined rate of change.";
return;
}
var changeInY = y2 – y1;
var changeInX = x2 – x1;
var averageRateOfChange = changeInY / changeInX;
resultDiv.innerHTML = "Average Rate of Change: " + averageRateOfChange.toFixed(4);
}