How numeric differentiation works
f′(x) ≈ [−f(x+2h) + 8f(x+h) − 8f(x−h) + f(x−2h)] ÷ (12h)
f″(x) ≈ [−f(x+2h) + 16f(x+h) − 30f(x) + 16f(x−h) − f(x−2h)] ÷ (12h²)
This is a 4th-order central-difference scheme: error scales as O(h⁴), much smaller than the simple (f(x+h) − f(x))/h forward difference. The calculator picks h ≈ 10⁻⁴ × max(1, |x|) which balances truncation error against floating-point round-off.
Worked example
For f(x) = x³ − 2x² + sin(x) at x = 2:
- f(2) = 8 − 8 + sin(2) ≈ 0.9093
- Analytical f′(x) = 3x² − 4x + cos(x); f′(2) = 12 − 8 + cos(2) ≈ 3.5839
- Analytical f″(x) = 6x − 4 − sin(x); f″(2) = 12 − 4 − sin(2) ≈ 7.0907
Syntax cheat sheet
| You write | Meaning |
|---|---|
x^3 | x³ |
3*x^2 | 3x² (the * is required) |
sqrt(x) | √x |
exp(x) or e^x | eˣ |
ln(x) | natural log |
log(x) | log₁₀(x) |
sin(pi*x) | sin(πx) |