Use 'x' as the variable. Supported: x^n, +, -, *, /
The value you want to check if the function crosses.
What is the Intermediate Value Theorem?
The Intermediate Value Theorem (IVT) is a fundamental principle in calculus. It states that if a function f is continuous on a closed interval [a, b], and k is any number between f(a) and f(b), then there exists at least one number c in the interval (a, b) such that f(c) = k.
Conditions for IVT
The function must be continuous on the closed interval [a, b].
The target value k must lie strictly between f(a) and f(b).
Practical Example
Suppose you have the function f(x) = x² – 4 and you want to know if there is a root (where f(x) = 0) between x = 1 and x = 3.
f(1) = 1² – 4 = -3
f(3) = 3² – 4 = 5
Since 0 is between -3 and 5, and the function is a polynomial (which is continuous), the IVT guarantees that there is at least one c between 1 and 3 where f(c) = 0.
How This Calculator Works
This tool evaluates your function at the endpoints of the interval. If the target value k is between the results, it applies the Bisection Method to estimate the exact value of c where the function hits your target.
function evaluateFunction(expr, x) {
try {
// Clean expression for JS evaluation
var cleanExpr = expr.replace(/\^/g, "**");
// Safe evaluation context
var fn = new Function('x', 'return ' + cleanExpr);
return fn(x);
} catch (e) {
return NaN;
}
}
function calculateIVT() {
var expr = document.getElementById("functionInput").value;
var a = parseFloat(document.getElementById("valA").value);
var b = parseFloat(document.getElementById("valB").value);
var k = parseFloat(document.getElementById("targetK").value);
var resultDiv = document.getElementById("ivt-result");
if (isNaN(a) || isNaN(b) || isNaN(k)) {
resultDiv.style.display = "block";
resultDiv.className = "error";
resultDiv.innerHTML = "Error: Please enter valid numbers for the interval and target value.";
return;
}
if (a >= b) {
resultDiv.style.display = "block";
resultDiv.className = "error";
resultDiv.innerHTML = "Error: Interval Start (a) must be less than Interval End (b).";
return;
}
var fa = evaluateFunction(expr, a);
var fb = evaluateFunction(expr, b);
if (isNaN(fa) || isNaN(fb)) {
resultDiv.style.display = "block";
resultDiv.className = "error";
resultDiv.innerHTML = "Error: Invalid function expression. Please check your syntax.";
return;
}
var minF = Math.min(fa, fb);
var maxF = Math.max(fa, fb);
var html = "f(a) = " + fa.toFixed(4) + "";
html += "f(b) = " + fb.toFixed(4) + "";
if (k >= minF && k <= maxF) {
resultDiv.className = "success";
html += "IVT Condition Met: Since " + k + " is between " + fa.toFixed(4) + " and " + fb.toFixed(4) + ", a value c exists such that f(c) = " + k + ".";
// Bisection Method to find c
var low = a;
var high = b;
var c = 0;
var iterations = 0;
// Target is to find f(x) – k = 0
while (iterations < 100) {
c = (low + high) / 2;
var fc = evaluateFunction(expr, c);
if (Math.abs(fc – k) < 0.0001) break;
// Adjust based on whether fa or fb is the lower end relative to k
var valLow = evaluateFunction(expr, low) – k;
var valMid = fc – k;
if (valLow * valMid < 0) {
high = c;
} else {
low = c;
}
iterations++;
}
html += "Estimated Value: c ≈ " + c.toFixed(6) + " where f(c) ≈ " + k;
} else {
resultDiv.className = "warning";
html += "IVT Does Not Guarantee a Value: The target value " + k + " is NOT between f(a) and f(b). A value c may or may not exist, but the theorem does not guarantee it for this interval.";
}
resultDiv.style.display = "block";
resultDiv.innerHTML = html;
}