Calculate Rate of Change of a Function

Rate of Change Calculator

The rate of change of a function describes how the output value of the function changes with respect to a change in its input value. For a function \(f(x)\), the average rate of change between two points \((x_1, f(x_1))\) and \((x_2, f(x_2))\) is given by the formula: $$ \text{Average Rate of Change} = \frac{f(x_2) – f(x_1)}{x_2 – x_1} $$ This is essentially the slope of the secant line connecting these two points on the graph of the function. If we consider the instantaneous rate of change at a single point \(x\), this is represented by the derivative of the function at that point, \(f'(x)\).

.calculator-container { font-family: sans-serif; max-width: 600px; margin: 20px auto; padding: 20px; border: 1px solid #ddd; border-radius: 8px; background-color: #f9f9f9; } .calculator-container h1 { text-align: center; color: #333; margin-bottom: 20px; } .calculator-container p { line-height: 1.6; color: #555; margin-bottom: 25px; } .input-section { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-bottom: 20px; } .input-section label { display: block; margin-bottom: 5px; font-weight: bold; color: #444; grid-column: span 1; } .input-section input[type="text"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; /* Ensure padding doesn't affect width */ grid-column: span 1; } .calculator-container button { display: block; width: 100%; padding: 12px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; margin-bottom: 20px; } .calculator-container button:hover { background-color: #0056b3; } .result-section { margin-top: 20px; padding: 15px; background-color: #e7f3fe; border: 1px solid #b3d7ff; border-radius: 4px; text-align: center; font-size: 18px; font-weight: bold; color: #0056b3; } function calculateRateOfChange() { var x1 = parseFloat(document.getElementById("x1").value); var fx1 = parseFloat(document.getElementById("fx1").value); var x2 = parseFloat(document.getElementById("x2").value); var fx2 = parseFloat(document.getElementById("fx2").value); var resultDiv = document.getElementById("result"); // Check if inputs are valid numbers if (isNaN(x1) || isNaN(fx1) || isNaN(x2) || isNaN(fx2)) { resultDiv.innerHTML = "Please enter valid numbers for all fields."; return; } // Check for division by zero if (x2 – x1 === 0) { resultDiv.innerHTML = "Cannot calculate rate of change: x₁ and x₂ cannot be the same."; return; } var rateOfChange = (fx2 – fx1) / (x2 – x1); resultDiv.innerHTML = "The average rate of change is: " + rateOfChange.toFixed(4); }

Leave a Comment