Derivative calculator

Numerically compute f′(x) and f″(x) at any point. Uses a 4th-order central-difference scheme that matches analytical derivatives to ~10 significant figures for smooth functions.

Derivative inputs

Use ^ for power. Functions: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, ln, log, sqrt, abs. Constants: pi, e. Multiplication is explicit (use 2*x, not 2x).
f′(x₀)
3.5839
f(x₀)
0.9093
f″(x₀)
3.0907
Step size used
1×10⁻⁴
Tangent line at x₀
y = 3.58x − 6.26

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 writeMeaning
x^3
3*x^23x² (the * is required)
sqrt(x)√x
exp(x) or e^x
ln(x)natural log
log(x)log₁₀(x)
sin(pi*x)sin(πx)

Related calculators