Numerical differentiation
From Wikipedia, the free encyclopedia
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.
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)). 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.
Contents |
[edit] Practical considerations
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. 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 sqrt(eps) * x where the machine epsilon eps is typically of the order 2.2e-16. Another important consideration is to make sure that h and x+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: h = sqrt(eps) * x, temp = x + h and h = temp − x. It may be necessary to declare temp as a volatile variable to ensure the steps are not undone by compiler optimization.
[edit] Higher order methods
Higher order methods for approximating the derivative, as well as methods for higher derivatives exist.
Below is the five point method for the first derivative (five-point stencil in one dimension).
[edit] References
- Richard L. Burden, J. Douglas Faires (2000), Numerical Analysis, (7th Ed), Brooks/Cole. ISBN 0-534-38216-9
[edit] See also
- Automatic differentiation
- Finite difference
- Five-point stencil
- Numerical integration
- Numerical ordinary differential equations
- Numerical smoothing and differentiation
[edit] External links
- http://mathworld.wolfram.com/NumericalDifferentiation.html
- http://math.fullerton.edu/mathews/n2003/NumericalDiffMod.html
- Numerical Derivatives Calculator Calculate the derivative of a function in any given point