‣

Numerical Differentiation

Numerical differentiation approximates the value of a true derivative, the slope of the tangent line, with a finite difference, giving the slope of a secant line, neglecting the limit. The following example equation and diagram show a forward difference approximation.

$$ f'(x)=\lim_{h\rarr\infin}\frac{f(x+h)-f(x)}{h}\approx\frac{f(x+h)-f(x)}{h} $$

Untitled

In order to derive the order of error for any given finite difference approximation, we’ll need to consider the Taylor series expansion for the function value at the sampled points.

$$ f_{i+1}=f_i+f'_ih+\frac 12f''_ih^2+... $$

$$ f_{i-1}=f_i-f'_ih+\frac 12f''_ih^2+... $$

The order of error of the forward difference may be found as the difference between the actual derivative, $f'i$, and the approximation, $\frac{f{i+1}-f_i}{h}$. By this process, the error is found to be $O(h)$.

$$ f'i-\frac{f{i+1}-f_i}{h}=f'_i-\frac{f_i+f'_ih+\frac 12f''_ih^2+...-f_i}{h}=f'_i-\frac{f'_ih+O(h^2)}{h}=O(h) $$

If we sample the function value at more points, we may account for higher derivatives, achieving smaller orders of error. In addition to the techniques tabulated below, there are many other possible approximations, for example, utilizing two backwards or forward differences to achieve $O(h^2)$ error.

Technique Equation
$O(h)$ Forward Difference $f'i=(f{i+1}-f_i)/h$
$O(h)$ Backward Difference $f'i=(f_i-f{i-1})/h$
$O(h^2)$ Centered Difference $f'i=(f{i+1}-f_{i-1})/2h$

Numerical Integration

Newton-Cotes formulas are the most common method. In effect, they approximate $n+1$ data points as an $n^{th}$ order polynomial. These may be expressed in the form $A=f_{avg}\cdot h$. The areas and truncation errors of a number of methods are tabulated below.

Rule Intervals Area Truncation Error
Midpoint 1 $hf_{0.5}$ $-\frac 13f^{(2)}(\xi)h^3$
Trapezoidal 1 $\frac 12h(f_0+f_1)$ $-\frac 1{12}f^{(2)}(\xi)h^3$
Simpson’s $\frac 13$ 2 $\frac 13h(f_0+4f_1+f_2)$ $-\frac 1{90}f^{(4)}(\xi)h^5$
Simpson’s $\frac 38$ 3 $\frac 38h(f_0+3f_1+3f_2+f_3)$ $-\frac 3{80}f^{(4)}(\xi)h^5$