TOPICS
Search

Numerical Differentiation


Numerical differentiation is the process of finding the numerical value of a derivative of a given function at a given point. Computing a derivative from nearby approximate function values can amplify data errors and roundoff error. The choice of step size must balance approximation error against this amplification. Numerical differentiation is implemented as ND[f, x, x0, Scale -> scale] in the Wolfram Language package NumericalCalculus` .

There are many applications where derivatives need to be computed numerically. The simplest approach simply uses the definition of the derivative

 f^'(x)=lim_(h->0)(f(x+h)-f(x))/h
(1)

by evaluating the difference quotient at a small nonzero step h. Nash (1990, p. 219) suggests h=sqrt(epsilon)(|x|+sqrt(epsilon)) as a starting choice for forward differences in floating-point arithmetic, where epsilon is the machine precision.

Another approach differentiates a Lagrange interpolating polynomial. For distinct nodes x_0, x_1, ..., x_n, let L_j(t) be the cardinal polynomial of polynomial degree at most n equal to 1 at x_j and 0 at the other nodes. Then, for an integer r with 0<=r<=n,

 f^((r))(x) approx sum_(j=0)^nf(x_j)L_j^((r))(x).
(2)

The approximation is exact for polynomials of polynomial degree at most n. Lyness and Moler (1966) adapt Neville's algorithm to numerical derivatives. Fornberg (1998) gives recursions for the corresponding weights on arbitrarily spaced distinct nodes.

For a real-valued function with a suitable analytic complex extension, complex step differentiation estimates a derivative from the imaginary part of a complex function value, avoiding the subtraction in a real finite difference approximation (Squire and Trapp 1998).

For sufficiently smooth f, Richardson extrapolation in h^2 can eliminate successive error terms of the centered estimate [f(x+h)-f(x-h)]/(2h) (Ridders 1982).

For f analytic on and inside the circle of radius rho>0 centered at x, the Cauchy integral formula for derivatives can be evaluated numerically by the periodic trapezoidal rule. For derivative order m and N>m samples, this gives

 f^((m))(x) approx (m!)/(Nrho^m)sum_(j=0)^(N-1)f(x+rhoomega^j)omega^(-jm),
(3)

where omega=e^(2pii/N). The choice of radius affects both quadrature error and roundoff sensitivity (Bornemann 2011, 2013).

Local polynomial least squares fits also give Savitzky-Golay filter estimates of derivatives, with weights computed from a basis of discrete orthogonal polynomials (Gorry 1990).

The available information determines which methods apply. When the operations that compute a function are accessible and differentiable, automatic differentiation applies the chain rule directly. For smooth sampled data, spectral differentiation differentiates a global approximation. The finite element method uses piecewise approximations on a mesh (Komarov et al. 2026).

When samples contain independent additive errors of common variance sigma^2, the centered finite difference [f(x+h)-f(x-h)]/(2h) acquires error variance sigma^2/(2h^2). The variance grows as h decreases even though the truncation error for a sufficiently smooth function decreases as O(h^2), where O denotes big-O notation. Estimation from noisy samples thus uses assumptions about the underlying signal, such as smoothness or a model for its evolution (Komarov et al. 2026).

Examples include fitting and differentiating a smoothing spline, or treating the derivative as a hidden component of the state in a Kalman filter or smoother. When the derivative is expected to have jumps, total variation regularization can penalize the sum of absolute differences between consecutive derivative estimates. This favors long runs of nearly constant slope, as in a noisy triangular waveform (Komarov et al. 2026).


See also

Automatic Differentiation, Complex Step Differentiation, Derivative, Differentiation, Euler-Maclaurin Integration Formulas, Finite Difference, Maclaurin-Cauchy Theorem, Numerical Integration, Savitzky-Golay Filter, Spectral Differentiation

Explore with Wolfram|Alpha

References

Bornemann, F. "Accuracy and Stability of Computing High-Order Derivatives of Analytic Functions by Cauchy Integrals." Found. Comput. Math. 11, 1-63, 2011. https://doi.org/10.1007/s10208-010-9075-z.Bornemann, F. "Optimal Contours for High-Order Derivatives." IMA J. Numer. Anal. 33, 403-412, 2013. https://doi.org/10.1093/imanum/drs030.Fornberg, B. "Calculation of Weights in Finite Difference Formulas." SIAM Rev. 40, 685-691, 1998. https://doi.org/10.1137/S0036144596322507.Gorry, P. A. "General Least-Squares Smoothing and Differentiation by the Convolution (Savitzky-Golay) Method." Anal. Chem. 62, 570-573, 1990. https://doi.org/10.1021/ac00205a007.Komarov, P.; van Breugel, F.; and Kutz, J. N. "A Taxonomy of Numerical Differentiation Methods." 17 Nov 2026. https://arxiv.org/abs/2512.09090v5.Lyness, J. N. and Moler, C. B. "Van der Monde Systems and Numerical Differentiation." Numer. Math. 8, 458-464, 1966. https://doi.org/10.1007/BF02166671.Nash, J. C. Compact Numerical Methods for Computers: Linear Algebra and Function Minimisation, 2nd ed. Bristol, England: Adam Hilger, p. 219, 1990. https://doi.org/10.1201/9781315139784.Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. "Numerical Derivatives." §5.7 in Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 180-184, 1992.Ridders, C. J. F. "Accurate Computation of F^'(x) and F^'(x)F^('')(x)." Adv. Eng. Softw. 4, 75-76, 1982. https://doi.org/10.1016/S0141-1195(82)80057-0.Squire, W. and Trapp, G. "Using Complex Variables to Estimate Derivatives of Real Functions." SIAM Rev. 40, 110-112, 1998. https://doi.org/10.1137/S003614459631241X.Weisstein, E. W. "Books about Numerical Methods." http://www.ericweisstein.com/encyclopedias/books/NumericalMethods.html.

Referenced on Wolfram|Alpha

Numerical Differentiation

Cite this as:

Weisstein, Eric W. "Numerical Differentiation." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/NumericalDifferentiation.html

Subject classifications