Numerical Derivative
Compute numerical derivative f-prime(x) by central difference for a simple function.
f-linha(x) ≈ —
Numerical differentiation by finite differences
A finite-difference approximation estimates the derivative of f(x) by sampling the function at nearby points. The plainest one is the forward difference: f'(x) ≈ (f(x+h) − f(x))/h, and the backward form is its mirror image. Both carry error O(h). Step up to the central difference f'(x) ≈ (f(x+h) − f(x−h))/(2h) and the error drops to O(h²). A 5-point stencil (−f(x+2h)+8f(x+h)−8f(x−h)+f(x−2h))/(12h) pushes that down to O(h⁴). The second derivative has its own formula: f''(x) ≈ (f(x+h)−2f(x)+f(x−h))/h². Keep h small, but resist going microscopic, because once it gets too tiny round-off cancellation takes over. Automatic differentiation (autograd in PyTorch, JAX) sidesteps all of this by applying the chain rule symbolically at runtime, so the numerical errors never show up.
Applications and context
Numerical derivatives turn up across physics simulation (CFD, FEM, electromagnetics), machine learning (gradient descent, though autodiff usually takes over from FD here), economics (marginal sensitivity), engineering control and computer graphics. Even a black-box function with no known analytic derivative can be differentiated this way.
FAQ
Which h should I use? A handy rule of thumb is h ≈ √ε for forward differences and h ≈ ∛ε for the central one, where ε is machine epsilon (about 10⁻⁸ and 10⁻⁵ in double precision).
Why not just shrink h indefinitely? When you subtract two numbers that are nearly equal, you lose significant digits. Below a certain h the error starts climbing again.
When is autodiff better? Any time you have the source code for f. It returns derivatives that are exact up to round-off and handles thousands of inputs at once in reverse mode, and that's exactly why every major ML framework relies on it.
Related Tools
Numeric Function Derivative
Computes numeric derivative of a math expression at a point using central difference method.
Numeric Function Integral
Computes a definite integral over an interval using composite Simpson 1 3 rule.
Paint Coverage Calculator
Compute paint liters needed for an area, given coverage per liter and coats.
Spread Duration (Numerical)
Computes the spread duration of a bond by finite differences, repricing the instrument for an up and a down move in the credit spread: (V− − V+)/(2·V0·Δs). While duration measures sensitivity to changes in the risk-free rate, spread duration isolates sensitivity to the credit spread, the premium the market charges for issuer risk. It's essential for managing credit portfolios, where spread risk often dominates. Enter the base price, the prices with higher and lower spread and the spread change used.
Vacation Pay Calculator (Brazil)
Calculate vacation pay with the constitutional third per Brazilian labor law (CLT). Enter gross salary and vacation days to get the estimated net amount.
Bench Press 1RM (Epley)
Estimates one-rep max (1RM) bench press by Epley formula.
The results provided by this tool are for general informational and educational purposes only and do not constitute professional, financial, medical, legal, tax or accounting advice. Always confirm important decisions with a qualified professional and official sources.