Example/Application: Finite Difference Schemes

Example 13.16.1   Suppose you sample a function at the discrete points $ n \Delta x$, $ n \in \mathbb{Z}$. In Figure 13.11 we sample the function $ f(x) = \sin x$ on the interval $ [-4,4]$ with $ \Delta x = 1/4$ and plot the data points.

Figure 13.11: Sine function sampling.
\includegraphics[height=4cm,width=7cm]{sindata.eps}

We wish to approximate the derivative of the function on the grid points using only the value of the function on those discrete points. From the definition of the derivative, one is lead to the formula

$\displaystyle f'(x) \approx \frac{f(x+\Delta x) - f(x)}{\Delta x}.$ (13.21)

Taylor's theorem states that

$\displaystyle f(x + \Delta x) = f(x) + \Delta x f'(x) + \frac{\Delta x^2}{2} f''(\xi).
$

Substituting this expression into our formula for approximating the derivative we obtain

$\displaystyle \frac{f(x+\Delta x) - f(x)}{\Delta x} = \frac{f(x) + \Delta x f'(...
...a x^2}{2} f''(\xi) - f(x) }{\Delta x}
= f'(x) + \frac{\Delta x}{2} f''(\xi).
$

Thus we see that the error in our approximation of the first derivative is $ \frac{\Delta x}{2} f''(\xi)$. Since the error has a linear factor of $ \Delta x$, we call this a first order accurate method. Equation  13.21 is called the forward difference scheme for calculating the first derivative. Figure 13.12 shows a plot of the value of this scheme for the function $ f(x) = \sin x$ and $ \Delta x = 1/4$. The first derivative of the function $ f'(x) = \cos x$ is shown for comparison.

Figure 13.12: Forward Difference Scheme Approximation of the Derivative.
\includegraphics[height=4cm,width=7cm]{fwdsin.eps}

Another scheme for approximating the first derivative is the centered difference scheme,

$\displaystyle f'(x) \approx \frac{f(x+\Delta x) - f(x-\Delta x)}{2 \Delta x}.
$

Expanding the numerator using Taylor's theorem,

  $\displaystyle \frac{f(x+\Delta x) - f(x-\Delta x)}{2 \Delta x}$    
  $\displaystyle \qquad= \frac{f(x) + \Delta x f'(x) + \frac{\Delta x^2}{2} f''(x)...
...) - \frac{\Delta x^2}{2} f''(x) + \frac{\Delta x^3}{6} f'''(\psi) }{2 \Delta x}$    
  $\displaystyle \qquad= f'(x) + \frac{\Delta x^2}{12}(f'''(\xi) + f'''(\psi)).$    

The error in the approximation is quadratic in $ \Delta x$. Therefore this is a second order accurate scheme. Below is a plot of the derivative of the function and the value of this scheme for the function $ f(x) = \sin x$ and $ \Delta x = 1/4$.

Figure 13.13: Centered Difference Scheme Approximation of the Derivative.
\includegraphics[height=4cm,width=7cm]{ctrsin.eps}

Notice how the centered difference scheme gives a better approximation of the derivative than the forward difference scheme.

david joyner 2008-11-22