The average rate of change (AROC) measures how much a function's output value changes, on average, with respect to its input value over a given interval. It's essentially the slope of the secant line connecting two points on the function's graph. A positive AROC indicates the function is increasing over the interval, a negative AROC indicates it's decreasing, and an AROC of zero means it's neither increasing nor decreasing on average.
function calculateAROC() {
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 fields.";
return;
}
if (x1 === x2) {
resultDiv.innerHTML = "The interval's x-values cannot be the same (x₁ = x₂). This would result in division by zero.";
return;
}
var deltaY = y2 – y1;
var deltaX = x2 – x1;
var aroc = deltaY / deltaX;
resultDiv.innerHTML = "The Average Rate of Change over the interval is: " + aroc.toFixed(4);
}
.calculator-container {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-container h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.calculator-container p {
color: #555;
line-height: 1.6;
margin-bottom: 20px;
}
.input-section {
margin-bottom: 20px;
}
.input-section label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-section input[type="number"] {
width: calc(100% – 20px);
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-container button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.result-section {
margin-top: 25px;
padding: 15px;
background-color: #e7f3ff;
border: 1px solid #b3d7ff;
border-radius: 5px;
text-align: center;
font-weight: bold;
color: #0056b3;
}