Sheng Wang

Central Finite Difference of Derivatives(中心有限差分)

This post derived the method of central finite difference for calculating derivatives, especially for first and second order derivatives, and finally arrive at perfect results. Example are provided to verify the results.

Taylor expansion

According to Taylor expansion, we have:

Derivatives

In physical field, it is first and second order derivatives, as well as other boundary(initial) functions or constants, that compose the differential control equations. So we only pay attention to the first and second order derivatives.
Adding and subtraction of $f(x+\delta)$ and $f(x-\delta)$ lead to:

(1) First order derivative

According to $\eqref{first}$, $f’(x)$ should be:

omitting tail items leads to $f’(x) = \frac{f(x+\delta) - f(x-\delta)}{2\delta}$. The accuracy is $O(\delta^2)$, known as second order accuracy.

(2) Second order derivative

In the same way, $f’’(x)$ is derived from $\eqref{second}$

omitting tail items leads to $f’’(x) = \frac{f(x+\delta) + f(x-\delta) - 2f(x)}{ \delta^2}$. The accuracy is $O(\delta^2)$, also know as second order accuaray.

Higher Order Accuracy

To increase the accuracy, $f’(x;\delta)$, $f’(x;2\delta)$, $f’(x;3\delta)$…etc are could be added together by appropriate ratios to counteract the items of $\delta^2$,$\delta^4$,$\delta^6$…etc. This method works for $f’’(x)$ as well.

(1) $f’(x)$

For step of $\delta$, $2\delta$, $3\delta$…etc, we have:

summing all these items proportionally from $f’(x;\delta)$ to $f’(x;N\delta)$ leads to:

so, if we want to have 2ith order accuracy, all item coefficients of $\sum \limits_{k=1}^N {C_k k^{**}}$ must have value of zero. Besides, to determine the value of $C_1,C_2,…,C_N$, $i$ should equals to $N$. So we arrive at a linear equation of $C$:

By calculation, $C_1,C_2,C_3,…,C_N$ have the value of:

(2) $f’’(x)$

For step of $\delta$, $2\delta$, $3\delta$…etc, we have:

summing all these items proportionally from $f’(x;\delta)$ to $f’(x;N\delta)$ leads to:

so, if we want to have 2ith order accuracy, all item coefficients of $\sum \limits_{k=1}^N {F_k k^{**}}$ must have value of zero. Besides, to determine the value of $F_1,F_2,…,F_N$, $i$ should equals to $N$. So we arrive at a linear equation of $F$, which is same as $\eqref{M_C}$.

Conclusion

To sum up, finite difference of 2Nth order accuracy for first or second order derivative are:

Values of $C_k$ are obtained by solving vandermonde equation.

by simplifying:

Values of $C_k$, $c_k$ and $f_k$ are:

order $C_{1}$ $C_{2}$ $C_{3}$ $C_{4}$ $C_{5}$ $C_{6}$
2 $1$
4 $4/3$ $-1/3$
6 $3/2$ $-3/5$ $1/10$
8 $8/5$ $-4/5$ $8/35$ $-1/35$
10 $5/3$ $-20/21$ $5/14$ $-5/63$ $1/126$
12 $12/7$ $-15/14$ $10/21$ $-1/7$ $2/77$ $-1/462$
order $c_{1}$ $c_{2}$ $c_{3}$ $c_{4}$ $c_{5}$ $c_{6}$
2 $0.5$
4 $2/3$ $-1/12$
6 $3/4$ $-3/20$ $1/60$
8 $4/5$ $-1/5$ $4/105$ $-1/280$
10 $5/6$ $-5/21$ $5/84$ $-5/504$ $1/1260$
12 $6/7$ $-15/56$ $5/63$ $-1/56$ $1/385$ $-1/5544$
order $f_{1}$ $f_{2}$ $f_{3}$ $f_{4}$ $f_{5}$ $f_{6}$
2 $1.0$
4 $4/3$ $-1/12$
6 $3/2$ $-3/20$ $1/90$
8 $8/5$ $-1/5$ $8/315$ $-1/560$
10 $5/3$ $-5/21$ $5/126$ $-5/1008$ $1/3150$
12 $12/7$ $-15/56$ $10/189$ $-1/112$ $2/1925$ $-1/16632$

Examples

Applying finite-difference method to calculate the first and second derivatives of $f(x)=sin(x)$, results of 2nd, 4th, 6th order accuracy are presented below, as well as their error.
Codes

What’s more

Method presented above applies to collocated grid and symmetric points only. Find method for staggered grid, and method for processing boundary points(asymmetric method).