- Numerical differentiation
-
Numerical differentiation is a technique of numerical analysis to produce an estimate of the derivative of a mathematical function or function subroutine using values from the function and perhaps other knowledge about the function.
Contents
Finite difference formulae
The simplest method is to use finite difference approximations.
A simple two-point estimation is to compute the slope of a nearby secant line through the points (x,f(x)) and (x+h,f(x+h)).[1] Choosing a small number h, h represents a small change in x, and it can be either positive or negative. The slope of this line is
This expression is Newton's difference quotient.
The slope of this secant line differs from the slope of the tangent line by an amount that is approximately proportional to h. As h approaches zero, the slope of the secant line approaches the slope of the tangent line. Therefore, the true derivative of f at x is the limit of the value of the difference quotient as the secant lines get closer and closer to being a tangent line:
Since immediately substituting 0 for h results in division by zero, calculating the derivative directly can be unintuitive.
A simple three-point estimation is to compute the slope of a nearby secant line through the points (x-h,f(x-h)) and (x+h,f(x+h)). The slope of this line is
More generally, three-point estimation uses the secant line through the points (x − h1,f(x − h1)) and (x + h2,f(x + h2)). The slope of this line is
The slope of these secant lines differ from the slope of the tangent line by an amount that is approximately proportional to h2 so that three-point estimation is a more accurate approximation to the tangent line than two-point estimation when h is small.
For the three-point estimation method, the estimation error is given by:
- ,
where c is some point between x − h and x + h. This error does not include the rounding error.
Practical considerations using floating point arithmetic
An important consideration in practice when the function is approximated using floating point arithmetic is how small a value of h to choose. If chosen too small, the subtraction will yield a large rounding error and in fact all the finite difference formulae are ill-conditioned[2] and due to cancellation will produce a value of zero if h is small enough.[3] If too large, the calculation of the slope of the secant line will be more accurate, but the estimate of the slope of the tangent by using the secant could be worse.
As discussed in Chapter 5.7 of Numerical Recipes in C (http://www.nrbook.com/a/bookcpdf/c5-7.pdf), a suitable choice for h is where the machine epsilon ε is typically of the order 2.2×10-16. Another important consideration is to make sure that h and 0+h are representable in floating point precision so that the difference between x+h and x is exactly h. This can be accomplished by placing their values into and out of memory as follows: , and . It may be necessary to declare ξ as a volatile variable so the steps are not undone by compiler optimization.
Higher order methods
Higher order methods for approximating the derivative, as well as methods for higher derivatives exist.
Given below is the five point method for the first derivative (five-point stencil in one dimension).
where .
More information about those methods can be found in the article about Finite difference methods, while a large set of numerical coefficients for those methods are tabulated in the article on Finite difference coefficient.
Differential quadrature
Differential quadrature is the approximation of derivatives by using weighted sums of function values.[4][5] The name is in analogy with quadrature meaning Numerical integration where weighted sums are used in methods such Simpson's method or the Trapezium rule. There are various methods for determining the weight coefficients. Differential quadrature is used to solve partial differential equations.
Complex variable methods
The classical finite difference approximations for numerical differentiation are ill-conditioned. However, if f is a holomorphic function, real-valued on the real line, which can be evaluated at points in the complex plane near x then there are stable methods. For example,[3] the first derivative can be calculated by the complex-step derivative formula:[6]
- .
In general, derivatives of any order can be calculated by the virtue of Cauchy's integral formula:
- ,
where the integration is done numerically.
Using complex variables for numerical differentiation was started by Lyness and Moler in 1967.[7] A method based on numerical inversion of a complex Laplace transform was developed by Abate and Dubner.[8] An algorithm which can be used without requiring knowledge about the method or the character of the function was developed by Fornberg.[2]
See also
- Automatic differentiation
- Finite difference
- Five-point stencil
- Numerical integration
- Numerical ordinary differential equations
- Numerical smoothing and differentiation
- List of numerical analysis software
Notes
- ^ Richard L. Burden, J. Douglas Faires (2000), Numerical Analysis, (7th Ed), Brooks/Cole. ISBN 0-534-38216-9
- ^ a b Numerical Differentiation of Analytic Functions, B Fornberg - ACM Transactions on Mathematical Software (TOMS), 1981
- ^ a b Using Complex Variables to Estimate Derivatives of Real Functions, W Squire, G Trapp - SIAM REVIEW, 1998
- ^ Differential Quadrature and Its Application in Engineering: Engineering Applications, Chang Shu, Springer, 2000, ISBN 978-1-85233-209-9
- ^ Advanced Differential Quadrature Methods, Yingyan Zhang, CRC Press, 2009, ISBN 978-1-4200-8248-7
- ^ Martins, JRRA; P Sturdza & JJ Alonso (2003) The Complex-Step Derivative Approximation ACM Transactions on Mathematical Software 29(3):245–262.
- ^ J. N. Lyness AND C. B. Moler, Numerical differentiation of analytic functions, SIAM J.Numer. Anal., 4 (1967), pp. 202-210.
- ^ A New Method for Generating Power Series Expansions of Functions, J Abate, H Dubner, SIAM J. Numer. Anal. Volume 5, Issue 1, pp. 102-112 (March 1968)
External links
- http://mathworld.wolfram.com/NumericalDifferentiation.html
- http://math.fullerton.edu/mathews/n2003/NumericalDiffMod.html
- Numerical Differentiation Resources: Textbook notes, PPT, Worksheets, Audiovisual YouTube Lectures at Numerical Methods for STEM Undergraduate
- Smooth Noise-Robust Numerical Derivative Numerical differentiation methods (including noisy functions/digital signals). Detailed coverage of central differences, Lanczos and smooth noise-robust differentiators with reference tables.
Categories:
Wikimedia Foundation. 2010.