Average Rate of Change Calculator (from Table Data)
This calculator helps you determine the average rate of change between two points on a function, given a table of data. The average rate of change represents the slope of the secant line connecting two points (x1, y1) and (x2, y2) on the graph of a function. It tells us how much the function's output (y-value) changes on average for each unit of change in the input (x-value) over a given interval.
Calculate Average Rate of Change
.calculator-container {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.calculator-container h2, .calculator-container h3 {
text-align: center;
color: #333;
}
.input-section {
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 15px;
}
.form-group {
margin-bottom: 15px;
display: flex;
align-items: center;
}
.form-group label {
flex: 1;
margin-right: 10px;
color: #555;
font-weight: bold;
}
.form-group input {
flex: 2;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Ensures padding doesn't affect width */
}
button {
display: block;
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.result-section {
margin-top: 20px;
text-align: center;
padding-top: 15px;
background-color: #f9f9f9;
border-radius: 4px;
}
#result {
font-size: 1.2em;
font-weight: bold;
color: #28a745;
}
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");
if (isNaN(x1) || isNaN(y1) || isNaN(x2) || isNaN(y2)) {
resultElement.textContent = "Please enter valid numbers for all inputs.";
resultElement.style.color = "red";
return;
}
if (x2 === x1) {
resultElement.textContent = "Cannot calculate rate of change when x1 equals x2 (division by zero).";
resultElement.style.color = "orange";
return;
}
var deltaY = y2 – y1;
var deltaX = x2 – x1;
var averageRateOfChange = deltaY / deltaX;
resultElement.textContent = "The average rate of change is: " + averageRateOfChange.toFixed(4);
resultElement.style.color = "#28a745";
}