
In
numerical analysis
Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic computation, symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of ...
, numerical differentiation
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s estimate the
derivative
In mathematics, the derivative is a fundamental tool that quantifies the sensitivity to change of a function's output with respect to its input. The derivative of a function of a single variable at a chosen input value, when it exists, is t ...
of a
mathematical function
In mathematics, a function from a set (mathematics), set to a set assigns to each element of exactly one element of .; the words ''map'', ''mapping'', ''transformation'', ''correspondence'', and ''operator'' are sometimes used synonymously. ...
or
subroutine
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a ...
using values of the function and perhaps other knowledge about the function.
Finite differences
The simplest method is to use finite difference approximations.
A simple two-point estimation is to compute the slope of a nearby
secant line
In geometry, a secant is a line (geometry), line that intersects a curve at a minimum of two distinct Point (geometry), points..
The word ''secant'' comes from the Latin word ''secare'', meaning ''to cut''. In the case of a circle, a secant inter ...
through the points and . Choosing a small number , represents a small change in , and it can be either positive or negative. The slope of this line is
This expression is
Newton's
difference quotient
In single-variable calculus, the difference quotient is usually the name for the expression
: \frac
which when taken to the Limit of a function, limit as ''h'' approaches 0 gives the derivative of the Function (mathematics), function ''f''. The ...
(also known as a first-order
divided difference).
The slope of this secant line differs from the slope of the tangent line by an amount that is approximately proportional to . As approaches zero, the slope of the secant line approaches the slope of the tangent line. Therefore, the true derivative of at 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 results in
indeterminate form
Indeterminate form is a mathematical expression that can obtain any value depending on circumstances. In calculus, it is usually possible to compute the limit of the sum, difference, product, quotient or power of two functions by taking the corres ...
, calculating the derivative directly can be unintuitive.
Equivalently, the slope could be estimated by employing positions and .
Another two-point formula is to compute the slope of a nearby secant line through the points and . The slope of this line is
This formula is known as the
symmetric difference quotient. In this case the first-order errors cancel, so the slope of these secant lines differ from the slope of the tangent line by an amount that is approximately proportional to
. Hence for small values of this is a more accurate approximation to the tangent line than the one-sided estimation. However, although the slope is being computed at , the value of the function at is not involved.
The estimation error is given by
where
is some point between
and
.
This error does not include the
rounding error
In computing, a roundoff error, also called rounding error, is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by the same algorithm using finite-precision, rounded arithmetic. Roun ...
due to numbers being represented and calculations being performed in limited precision.
The symmetric difference quotient is employed as the method of approximating the derivative in a number of calculators, including
TI-82,
TI-83,
TI-84,
TI-85, all of which use this method with .
Step size
An important consideration in practice when the function is calculated using
floating-point arithmetic
In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a Sign (mathematics), signed sequence of a fixed number of digits in some Radix, base) multiplied by an integer power of that ba ...
of finite precision is the choice of step size, . If chosen too small, the subtraction will yield a large
rounding error
In computing, a roundoff error, also called rounding error, is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by the same algorithm using finite-precision, rounded arithmetic. Roun ...
. In fact, all the finite-difference formulae are
ill-conditioned
In numerical analysis, the condition number of a function measures how much the output value of the function can change for a small change in the input argument. This is used to measure how sensitive a function is to changes or errors in the inpu ...
[Numerical Differentiation of Analytic Functions, B Fornberg – ACM Transactions on Mathematical Software (TOMS), 1981.] and due to cancellation will produce a value of zero if is small enough.
[Using Complex Variables to Estimate Derivatives of Real Functions, W. Squire, G. Trapp – SIAM REVIEW, 1998.] If too large, the calculation of the slope of the secant line will be more accurately calculated, but the estimate of the slope of the tangent by using the secant could be worse.
For basic central differences, the optimal step is the cube-root of
machine epsilon.
For the numerical derivative formula evaluated at and , a choice for that is small without producing a large rounding error is
(though not when ''x'' = 0), where the
machine epsilon is typically of the order of for
double precision
Double-precision floating-point format (sometimes called FP64 or float64) is a floating-point arithmetic, floating-point computer number format, number format, usually occupying 64 Bit, bits in computer memory; it represents a wide range of numeri ...
. A formula for that balances the rounding error against the secant error for optimum accuracy is
(though not when
), and to employ it will require knowledge of the function.
For computer calculations the problems are exacerbated because, although necessarily holds a
representable floating-point number in some precision (32 or 64-bit, ''etc''.), almost certainly will not be exactly representable in that precision. This means that will be changed (by rounding or truncation) to a nearby machine-representable number, with the consequence that will ''not'' equal ; the two function evaluations will not be exactly apart. In this regard, since most decimal fractions are recurring sequences in binary (just as 1/3 is in decimal) a seemingly round step such as will not be a round number in binary; it is 0.000110011001100...
2 A possible approach is as follows:
h := sqrt(eps) * x;
xph := x + h;
dx := xph - x;
slope := (F(xph) - F(x)) / dx;
However, with computers,
compiler optimization
An optimizing compiler is a compiler designed to generate code that is optimized in aspects such as minimizing program execution time, memory usage, storage size, and power consumption. Optimization is generally implemented as a sequence of op ...
facilities may fail to attend to the details of actual computer arithmetic and instead apply the axioms of mathematics to deduce that and are the same. With
C and similar languages, a directive that is a
volatile variable will prevent this.
Other methods
Higher-order methods
To obtain more general derivative approximation formulas for some function
, let
be a positive number close to zero. The Taylor expansion of
about the base point
is
Replacing
by
gives
Multiplying identity () by 4 gives
Subtracting identity () from () eliminates the
term:
which can be written as
Rearranging terms gives
which is called the three-point forward difference formula for the derivative. Using a similar approach, one can show
which is called the three-point central difference formula, and
which is called the three-point backward difference formula.
By a similar approach, the five point midpoint approximation formula can be derived as:
Numerical Example
Consider approximating the derivative of
at the point
.
Since
, the exact value is
Code
The following is an example of a
Python implementation for finding derivatives numerically for
using the various three-point difference formulas at
. The function
func
has derivative
func_prime
.
Higher derivatives
Using Newton's difference quotient,
the following can be shown (for ):
Complex-variable methods
The classical finite-difference approximations for numerical differentiation are ill-conditioned. However, if
is a
holomorphic function
In mathematics, a holomorphic function is a complex-valued function of one or more complex variables that is complex differentiable in a neighbourhood of each point in a domain in complex coordinate space . The existence of a complex de ...
, real-valued on the real line, which can be evaluated at points in the complex plane near
, then there are
stable
A stable is a building in which working animals are kept, especially horses or oxen. The building is usually divided into stalls, and may include storage for equipment and feed.
Styles
There are many different types of stables in use tod ...
methods. For example,
[ the first derivative can be calculated by the complex-step derivative formula:
The recommended step size to obtain accurate derivatives for a range of conditions is .]
This formula can be obtained by Taylor series
In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor ser ...
expansion:
The complex-step derivative formula is only valid for calculating first-order derivatives. A generalization of the above for calculating derivatives of any order employs multicomplex numbers, resulting in multicomplex derivatives.
where the denote the multicomplex imaginary units; . The operator extracts the th component of a multicomplex number of level , e.g., extracts the real component and extracts the last, “most imaginary” component. The method can be applied to mixed derivatives, e.g. for a second-order derivative
A C++ implementation of multicomplex arithmetics is available.
In general, derivatives of any order can be calculated using Cauchy's integral formula
In mathematics, Cauchy's integral formula, named after Augustin-Louis Cauchy, is a central statement in complex analysis. It expresses the fact that a holomorphic function defined on a disk is completely determined by its values on the boundary o ...
:
where the integration is done numerically.
Using complex variables for numerical differentiation was started by Lyness and Moler in 1967. Their algorithm is applicable to higher-order derivatives.
A method based on numerical inversion of a complex Laplace transform
In mathematics, the Laplace transform, named after Pierre-Simon Laplace (), is an integral transform that converts a Function (mathematics), function of a Real number, real Variable (mathematics), variable (usually t, in the ''time domain'') to a f ...
was developed by Abate and Dubner. An algorithm that can be used without requiring knowledge about the method or the character of the function was developed by Fornberg.[
]
Differential quadrature
Differential quadrature is the approximation of derivatives by using weighted sums of function values. Differential quadrature is of practical interest because its allows one to compute derivatives from noisy data. The name is in analogy with ''quadrature'', meaning numerical integration
In analysis, numerical integration comprises a broad family of algorithms for calculating the numerical value of a definite integral.
The term numerical quadrature (often abbreviated to quadrature) is more or less a synonym for "numerical integr ...
, where weighted sums are used in methods such as Simpson's rule or the trapezoidal rule. There are various methods for determining the weight coefficients, for example, the Savitzky–Golay filter. Differential quadrature is used to solve partial differential equations
In mathematics, a partial differential equation (PDE) is an equation which involves a multivariable function and one or more of its partial derivatives.
The function is often thought of as an "unknown" that solves the equation, similar to how ...
.
There are further methods for computing derivatives from noisy data.
See also
*
*
*List of numerical-analysis software
Listed here are notable end-user computer applications intended for use with numerical or data analysis:
Numerical-software packages
* Analytica is a widely used proprietary software tool for building and analyzing numerical models. It is a de ...
*
*
*
References
External links
Numerical Differentiation
from wolfram.com
* ttps://sinews.siam.org/Details-Page/differentiation-without-a-difference Differentiation With(out) a Differenceby Nicholas Higham, SIAM News.
{{DEFAULTSORT:Numerical Differentiation
Numerical analysis
Differential calculus