Skip to content
Sahithyan's S2
Sahithyan's S2 — Methods of Mathematics

Numerical Differentiation

Approximate numerical formulae can be derived using Taylor series.

For all the definitions below, hh is a small positive number, and is called the step size.

First Order Derivative

Taylor series expansion of f(x0+h)f(x_0+h) around x0x_0, truncated after 1st1^{\text{st}} derivative.

f(x0)=f(x0+h)f(x0)h+h2!f(2)(ϵ)f'(x_0) = \frac{f(x_0+h) - f(x_0)}{h} + \frac{h}{2!} f^{(2)}(\epsilon)

Error is bounded by:

Mh2\frac{M \lvert h \rvert}{2}

Forward difference formula

f(x0)=f(x0+h)f(x0)h+O(h)f'(x_0) = \frac{f(x_0+h) - f(x_0)}{h} + O(h)

Here MM is a bound on f(2)(x)f^{(2)}(x) between x0x_0 and x0+hx_0 + h.

Backward difference formula

f(x0)f(x0)f(x0h)h+O(h)f'(x_0) \approx \frac{f(x_0) - f(x_0 - h)}{h} + O(h)

Here MM is a bound on f(2)(x)f^{(2)}(x) between x0x_0 and x0hx_0 - h.

Centered difference formula

Aka. three-point mid point formula. Truncated after 2nd2^{\text{nd}} derivative.

f(x0)=f(x0+h)f(x0h)2h+O(h2)f'(x_0) = \frac{f(x_0 + h) - f(x_0 - h)}{2h} + O(h^2)

Error is in order of O(h2)O(h^2) which is better than O(h)O(h).

Second Order Derivatives

Second forward difference formula

f(2)(x0)=1h2[f(x0+2h)2f(x0+h)+f(x0)]+O(h)f^{(2)}(x_0) = \frac{1}{h^2} \Big[ f(x_0 + 2h) - 2f(x_0 + h) + f(x_0) \Big] + O(h)

Second backward difference formula

f(2)(x0)=1h2[f(x0)2f(x0h)+f(x02h)]+O(h)f^{(2)}(x_0) = \frac{1}{h^2} \Big[ f(x_0) - 2f(x_0 - h) + f(x_0 - 2h) \Big] +O(h)

Second centered difference formula

f(2)(x0)=1h2[f(x0+h)2f(x0)+f(x0h)]+O(h2)f^{(2)}(x_0) = \frac{1}{h^2} \Big[ f(x_0 + h) - 2f(x_0) + f(x_0 - h) \Big] + O(h^2)

Higher Order Derivatives

For nn-th derivative, Taylor series is truncated after nthn^{\text{th}} derivative.

n-th forward difference formula

f(n)(x)=1hni=0n(1)ni(ni)f(x+ih)+O(h)f^{(n)}(x) = \frac{1}{h^n} \sum_{i=0}^{n} (-1)^{n-i} \binom{n}{i} f(x + ih) + O(h)

n-th backward difference formula

f(n)(x)=1hni=0n(1)i(ni)f(xih)+O(h)f^{(n)}(x) = \frac{1}{h^n} \sum_{i=0}^{n} (-1)^i \binom{n}{i} f(x - ih) + O(h)

n-th centered difference formula

f(n)(x)=1hni=0n(1)i(ni)f(x+(n2i)h)+O(h2)f^{(n)}(x)= \frac{1}{h^n} \sum_{i=0}^{n} (-1)^i \binom{n}{i} f\left(x + \left(\frac{n}{2} - i\right)h\right) + O(h^2)

Accuracy

The accuracy of these divided difference formulas can be increased by including additional terms in the Taylor series. In each step the accuracy is improved by a power of hh.

f(x0)=1h[32f(x0)+2f(x0+h)12f(x0+2h)]+O(h2)f'(x_0) = \frac{1}{h} \left[ -\frac{3}{2} f(x_0) +2f(x_0+h) -\frac{1}{2}f(x_0+2h) \right] +O(h^2)