Numerical differentiation
estimation of derivative|230px|right In numerical analysis, numerical differentiation algorithms estimate the derivative of a mathematical function or subroutine using values of the function.[src] Unlike analytical differentiation, which provides exact expressions for derivatives, numerical differentiation relies on the function's values at a set of discrete points to estimate the derivative's value at those points or at intermediate points.[src] This approach is particularly useful when dealing with data obtained from experiments, simulations, or situations where the function is defined only at specific intervals.[src]
estimation of derivative|230px|right]] In numerical analysis, numerical differentiation algorithms estimate the derivative of a mathematical function or subroutine using values of the function.[src] Unlike analytical differentiation, which provides exact expressions for derivatives, numerical differentiation relies on the function's values at a set of discrete points to estimate the derivative's value at those points or at intermediate points.[src] This approach is particularly useful when dealing with data obtained from experiments, simulations, or situations where the function is defined only at specific intervals.[src] ==Finite differences== The simplest method is to use finite difference approximations.[src] A simple two-point estimation is to compute the slope of a nearby secant line through the points and .[src] Choosing a small number , represents a small change in , and it can be either positive or negative.[src] The slope of this line is \frac{f(x + h) - f(x)}{h}.[src] This expression is Newton's difference quotient (also known as a first-order divided difference).[src] To obtain an error estimate for this approximation, one can use Taylor expansion of f(x) about the base point x to give f(x+h) = f(x) + hf'(x) + \frac{h^2}{2}f(c) for some c between x and x+h .[src] Rearranging gives f'(x) = \underbrace{\frac{f(x+h) - f(x)}{h}}_{\text{Slope of secant line}} - \underbrace{\frac{h}{2}f(c)}_{\text{Error term}}.[src] The slope of this secant line differs from the slope of the tangent line by an amount that is approximately proportional to .[src] As approaches zero, the slope of the secant line approaches the slope of the tangent line and the error term vanishes.[src] 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: f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}.[src] Since immediately substituting 0 for results in \frac{0}{0} indeterminate form, calculating the derivative directly can be unintuitive.[src] Equivalently, the slope could be estimated by employing positions and .[src] Another two-point formula is to compute the slope of a nearby secant line through the points and .[src] The slope of this line is \frac{f(x + h) - f(x - h)}{2h}.[src] This formula is known as the symmetric difference quotient.[src] 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 h^2 .[src] Hence for small values of this is a more accurate approximation to the tangent line than the one-sided estimation.[src] However, although the slope is being computed at , the value of the function at is not involved.[src] The estimation error is given by R = \frac{-f^{(3)}(c)}{6} h^2, where c is some point between x - h and x + h .[src] This error does not include the rounding error due to numbers being represented and calculations being performed in limited precision.[src] 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 .[src] ==Step size== An important consideration in practice when the function is calculated using floating-point arithmetic of finite precision is the choice of step size, .[src] To illustrate, consider the two-point approximation formula with error term: f'(x) = \frac{f(x+h) - f(x-h)}{2h} - \frac{f^{(3)}(c)}{6}h^2 where c is some point between x - h and x + h .[src] Let e(x) denote the roundoff error encountered when evaluating the function f(x) and \hat{f}(x) denote the computed value of f(x) .[src] Therefore, f(x) = \hat{f}(x) + e(x).[src] The total error in the approximation is f'(x) - \frac{\hat{f}(x + h) - \hat{f}(x-h)}{2h} = \underbrace{\frac{e(x + h) - e(x-h)}{2h}}_{\text{Roundoff error}} - \underbrace{\frac{f^{(3)}(c)}{6}h^2}_{\text{Truncation error}}.[src] Assuming that the roundoff errors are bounded by some number \varepsilon > 0 and the third derivative of f(x) is bounded by some number M > 0 , we get \left| f'(x) - \frac{\hat{f}(x + h) - \hat{f}(x-h)}{2h} \right| \le \frac{\varepsilon}{h} + \frac{h^2}{6}M.[src] To reduce the truncation error \frac{h^2}{6}M , we must reduce .[src] But as is reduced, the roundoff error \frac{\varepsilon}{h} increases.[src] Due to the need to divide by the small value , all the finite-difference formulae for numerical differentiation are similarly ill-conditioned.[src] If instead the derivative is approximated using f'(x) = \frac{f(x+h) - f(x)}{h} and we assume the relative approximation error due to rounding is bounded by machine epsilon and the values |f(x)| and |f(x)| are bounded on [x_0,x_0+h] by M_1 and M_2 respectively it can be shown that: \left| f'(x_0) - \frac{\hat{f}(x_0 + h) - \hat{f}(x_0)}{h} \right| \le \frac{h}{2}M_1 + \frac{2\varepsilon}{h}M_2 By minimizing this upper bound an estimate for the optimal step size can be obtained.[src] However, employing this method would require the knowledge of the bounds M_1 and M_2 .[src] Instead, if an approximate upper bound is used - one where M_1 and M_2 are replaced by |f(x_0)| and |f(x_0)| the error can be estimated as: e(h) = \frac{h}{2}|f(x_0)| + \frac{2\varepsilon}{h}|f(x_0)| By minimizing e(h) an estimate for the optimal step size can be found: h = 2\sqrt{\varepsilon\left|\frac{f(x)}{f(x)}\right|} (though not when f(x) = 0 ).[src] If no information about the function f is known, sometimes the approximation \sqrt{\left| \frac{f(x)}{f(x)} \right|} \approx x is used giving a choice for that is small without producing a large rounding error: \sqrt{\varepsilon} x , where the machine epsilon is typically of the order of for double precision.[src] In practice, one cannot compute the value that minimizes the above error bounds and therefore cannot compute an approximation of the optimal step size without information about higher-order derivatives.[src] f(x) = \frac{2x}{1 + \sqrt{x}} at the point x_{0} = 9 .[src] In this case, we can calculate f'(x) = \frac{2 + \sqrt{x}}{(1 + \sqrt{x})^{2}} which gives f'(9) = \frac{2 + \sqrt{9}}{(1 + \sqrt{9})^{2}} = \frac{2 + 3}{(1 + 3)^{2}} = \frac{5}{16} = 0.3125.[src] Using 64-bit floating point numbers, the following approximations are generated with the two-point approximation formula and increasingly smaller step sizes.[src] The smallest absolute error is produced for a step size of 10^{-4} , after which the absolute error steadily increases as the roundoff errors dominate calcuations.[src] 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.[src] 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.[src] 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...[src] 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 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.[src] With C and similar languages, a directive that is a volatile variable will prevent this.[src] ==Three Point methods== To obtain more general derivative approximation formulas for some function f(x) , let h>0 be a positive number close to zero.[src] The Taylor expansion of f(x) about the base point x is {{NumBlk|::| f(x+h) = f(x) + hf'(x) + \frac{h^{2}}{2!}f(x) + \frac{h^{3}}{3!}f(x) + ...[src] | }} Replacing h by 2h gives {{NumBlk|::| f(x+2h) = f(x) + 2hf'(x) + \frac{4h^{2}}{2!}f(x) + \frac{8h^{3}}{3!}f(x) + ...[src] | }} Multiplying identity ( ) by 4 gives {{NumBlk|::| 4f(x+h) = 4f(x) + 4hf'(x) + \frac{4h^{2}}{2!}f(x) + \frac{4h^{3}}{3!}f(x) + ...[src] | }} Subtracting identity ( ) from ( ) eliminates the h^{2} term: f(x+2h) - 4f(x+h) = -3f(x) -2hf'(x) + \frac{4h^{3}}{3!}f(x) + ...[src] which can be written as f(x+2h) - 4f(x+h) = -3f(x) -2hf'(x) + O(h^{3}).[src] Rearranging terms gives f'(x) = \frac{-3f(x) + 4f(x+h) -f(x+2h)}{2h} + O(h^{2}), which is called the three-point forward difference formula for the derivative.[src] Using a similar approach, one can show f'(x) = \frac{f(x+h) - f(x-h)}{2h} + O(h^{2}) which is called the three-point central difference formula, and f'(x) = \frac{f(x-2h) -4f(x-h) + 3f(x)}{2h} + O(h^{2}) which is called the three-point backward difference formula.[src] By a similar approach, the five point midpoint approximation formula can be derived as: f'(x) = \frac{-f(x + 2h) + 8 f(x + h) - 8 f(x - h) + f(x - 2h)}{12h} + O(h^{4}).[src] Consider approximating the derivative of f(x)=x \sin{x} at the point x_{0} = \frac{\pi}{4} .[src] Since f'(x)=\sin{x} + x \cos{x} , the exact value is f'\left( \frac{\pi}{4} \right) = \sin \left(\frac{\pi}{4} \right) + \frac{\pi}{4}\cos \left(\frac{\pi}{4} \right) = \frac{1}{\sqrt{2}} + \frac{\pi}{4\sqrt{2}} \approx 1.2624671484563432.[src] f(x + h) = f(x) + f'(x)h + \frac{1}{2}f(x)h^{2} + \frac{1}{6}f(x)h^{3} + \frac{1}{24}f^{(4)}(\xi_{1})h^{4} and f(x - h) = f(x) - f'(x)h + \frac{1}{2}f(x)h^{2} - \frac{1}{6}f(x)h^{3} + \frac{1}{24}f^{(4)}(\xi_{2})h^{4} where x - h .[src] Adding these two equations gives f(x + h) + f(x - h) = 2f(x) + f(x)h^{2} + \frac{1}{24} \left[ f^{(4)}(\xi_{1}) + f^{(4)}(\xi_{2})\right]h^{4}.[src] If f^{(4)} is continuous on [x-h, x+h] , then \frac{1}{2}\left[ f^{(4)}(\xi_{1}) + f^{(4)}(\xi_{2})\right] is between f^{(4)}(\xi_{1}) and f^{(4)}(\xi_{2}) .[src] The Intermediate Value Theorem guarantees a number, say \xi , between \xi_{1} and \xi_{2} .[src] We can therefore write f(x) = \frac{1}{h^{2}} \left[f(x - h) - 2f(x) + f(x+h) \right] - \frac{h^2}{12}f^{(4)}(\xi).[src] where x - h .[src] Consider approximating the second derivative of the function f(x) = e^{x} \sin{x} at the point x_{0} = \frac{\pi}{4} .[src] Since f(x) = 2e^{x} \cos{x} , the exact value is f(\frac{\pi}{4}) = \sqrt{2}e^{\frac{\pi}{4}} \approx 3.1017663 .[src] f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h} the following can be shown (for ): f^{(n)}(x) = \lim_{h\to 0} \frac{1}{h^n} \sum_{k=0}^n (-1)^{n-k} \binom{n}{k} f(x + kh) ==Complex-variable methods== The classical finite-difference approximations for numerical differentiation are ill-conditioned.[src] 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.[src] For example, the first derivative can be calculated by the complex-step derivative formula: f'(x) = \frac{\Im(f(x + \mathrm{i}h))}{h} + O(h^2), \quad \mathrm{i^2}:=-1.[src] The recommended step size to obtain accurate derivatives for a range of conditions is h = 10^{-200} .[src] This formula can be obtained by Taylor series expansion: f(x+\mathrm{i}h) = f(x) + \mathrm{i}h f'(x) - \tfrac{1}{2!} h^2 f(x) - \tfrac{\mathrm{i}}{3!} h^3 f^{(3)}(x) + \cdots.[src] The complex-step derivative formula is only valid for calculating first-order derivatives.[src] A generalization of the above for calculating derivatives of any order employs multicomplex numbers, resulting in multicomplex derivatives.[src] f^{(n)}(x) \approx \frac{\mathcal{C}^{(n)}_{n^2-1}(f(x + \mathrm{i}^{(1)} h + \cdots + \mathrm{i}^{(n)} h))}{h^n} where the \mathrm{i}^{(k)} denote the multicomplex imaginary units; \mathrm{i}^{(1)} \equiv \mathrm{i} .[src] The \mathcal{C}^{(n)}_k operator extracts the k th component of a multicomplex number of level n , e.g., \mathcal{C}^{(n)}_0 extracts the real component and \mathcal{C}^{(n)}_{n^2-1} extracts the last, "most imaginary" component.[src] The method can be applied to mixed derivatives, e.g.[src] for a second-order derivative \frac{\partial^2 f(x, y)}{\partial x \,\partial y} \approx \frac{\mathcal{C}^{(2)}_3(f(x + \mathrm{i}^{(1)} h, y + \mathrm{i}^{(2)} h))}{h^2} A C++ implementation of multicomplex arithmetics is available.[src] In general, derivatives of any order can be calculated using Cauchy's integral formula: f^{(n)}(a) = \frac{n!}{2\pi i} \oint_\gamma \frac{f(z)}{(z - a)^{n+1}} \,\mathrm{d}z, where the integration is done numerically.[src] Using complex variables for numerical differentiation was started by Lyness and Moler in 1967.[src] Their algorithm is applicable to higher-order derivatives.[src] A method based on numerical inversion of a complex Laplace transform was developed by Abate and Dubner.[src] An algorithm that can be used without requiring knowledge about the method or the character of the function was developed by Fornberg.[src] ==Differential quadrature== Differential quadrature is the approximation of derivatives by using weighted sums of function values.[src] Differential quadrature is of practical interest because its allows one to compute derivatives from noisy data.[src] The name is in analogy with quadrature, meaning numerical integration, where weighted sums are used in methods such as Simpson's rule or the trapezoidal rule.[src] There are various methods for determining the weight coefficients, for example, the Savitzky–Golay filter.[src] Differential quadrature is used to solve partial differential equations.[src] There are further methods for computing derivatives from noisy data.[src] ==See also== List of numerical-analysis software ==References==[src]
92 sentences · 92 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Numerical differentiation." encyclopegia.org, 2026, https://encyclopegia.org/wiki/numerical-differentiation. Accessed 04 December 2026.
Chicago
"Numerical differentiation." encyclopegia.org. Accessed December 4, 2026. https://encyclopegia.org/wiki/numerical-differentiation.
APA
encyclopegia.org. (2026). Numerical differentiation. Retrieved December 4, 2026, from https://encyclopegia.org/wiki/numerical-differentiation
Accessed December 4, 2026 · CC BY-SA 4.0 · citation page · JSON