This calculator helps you determine the average rate of change of a function between two points on a graph. The average rate of change represents the slope of the secant line connecting two points on the function's curve. It's a fundamental concept in calculus and helps understand how a function's value changes, on average, over an interval.
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 resultElement = document.getElementById("result");
resultElement.innerHTML = ""; // Clear previous results
if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) {
resultElement.innerHTML = "Please enter valid numbers for all coordinates.";
return;
}
if (x1 === x2) {
resultElement.innerHTML = "The x-coordinates cannot be the same (x₁ = x₂), as this would result in division by zero.";
return;
}
// Formula for Average Rate of Change: (y₂ – y₁) / (x₂ – x₁)
var averageRateOfChange = (y2 – y1) / (x2 – x1);
resultElement.innerHTML = "The average rate of change between the points (" + x1 + ", " + y1 + ") and (" + x2 + ", " + y2 + ") is: " + averageRateOfChange.toFixed(4) + "";
}
#averageRateOfChangeCalculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
#averageRateOfChangeCalculator h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.input-section {
margin-bottom: 15px;
}
.input-section label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-section input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
#averageRateOfChangeCalculator button {
display: block;
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-top: 10px;
transition: background-color 0.3s ease;
}
#averageRateOfChangeCalculator button:hover {
background-color: #0056b3;
}
.result-section {
margin-top: 20px;
padding: 15px;
border: 1px solid #e0e0e0;
background-color: #fff;
border-radius: 4px;
text-align: center;
}
.result-section p {
margin: 0;
font-size: 1.1em;
color: #333;
}
.result-section strong {
color: #28a745;
}