# Finite difference coefficient

In mathematics, to approximate a derivative to an arbitrary order of accuracy, it is possible to use the finite difference. A finite difference can be central, forward or backward.

## Central finite difference

This table contains the coefficients of the central differences, for several orders of accuracy and with uniform grid spacing:[1]

Derivative Accuracy −5−4−3−2−1012345
1 2 −1/201/2
4 1/12−2/302/3−1/12
6 −1/603/20−3/403/4−3/201/60
8 1/280−4/1051/5−4/504/5−1/54/105−1/280
2 2 1−21
4 −1/124/3−5/24/3−1/12
6 1/90−3/203/2−49/183/2−3/201/90
8 −1/5608/315−1/58/5−205/728/5−1/58/315−1/560
3 2 −1/210−11/2
4 1/8−113/80−13/81−1/8
6 −7/2403/10−169/12061/300−61/30169/120−3/107/240
4 2 1−46−41
4 −1/62−13/228/3−13/22−1/6
6 7/240−2/5169/60−122/1591/8−122/15169/60−2/57/240
5 2 −1/22−5/205/2−21/2
4 1/6−3/213/3−29/6029/6−13/33/2−1/6
6 −13/28819/36−87/3213/2−323/480323/48−13/287/32−19/3613/288
6 2 1−615−2015−61
4 −1/43−1329−75/229−133−1/4
6 13/240−19/2487/16−39/2323/8−1023/20323/8−39/287/16−19/2413/240

For example, the third derivative with a second-order accuracy is

${\displaystyle f'''(x_{0})\approx {\frac {-{\frac {1}{2}}f(x_{-2})+f(x_{-1})-f(x_{+1})+{\frac {1}{2}}f(x_{+2})}{h_{x}^{3}}}+O\left(h_{x}^{2}\right),}$

where ${\displaystyle h_{x}}$ represents a uniform grid spacing between each finite difference interval, and ${\displaystyle x_{n}=x_{0}+nh_{x}}$.

For the ${\displaystyle m}$-th derivative with accuracy ${\displaystyle n}$, there are ${\displaystyle 2p+1=2\left\lfloor {\frac {m+1}{2}}\right\rfloor -1+n}$ central coefficients ${\displaystyle a_{-p},a_{-p+1},...,a_{p-1},a_{p}}$. These are given by the solution of the linear equation system

${\displaystyle {\begin{pmatrix}1&1&...&1&1\\-p&-p+1&...&p-1&p\\(-p)^{2}&(-p+1)^{2}&...&(p-1)^{2}&p^{2}\\...&...&...&...&...\\...&...&...&...&...\\...&...&...&...&...\\(-p)^{2p}&(-p+1)^{2p}&...&(p-1)^{2p}&p^{2p}\end{pmatrix}}{\begin{pmatrix}a_{-p}\\a_{-p+1}\\a_{-p+2}\\...\\...\\...\\a_{p}\end{pmatrix}}={\begin{pmatrix}0\\0\\0\\...\\m!\\...\\0\end{pmatrix}},}$

where the only non-zero value on the right hand side is in the ${\displaystyle (m+1)}$-th row.

An open source implementation for calculating finite difference coefficients of arbitrary derivate and accuracy order in one dimension is available.[2]

## Forward finite difference

This table contains the coefficients of the forward differences, for several orders of accuracy and with uniform grid spacing:[1]

Derivative Accuracy 0 1 2 3 4 5 6 7 8
1 111
23/221/2
311/633/21/3
425/12434/31/4
5137/605510/35/41/5
649/20615/220/315/46/51/6
2 1121
22541
335/1226/319/214/311/12
415/477/6107/61361/125/6
5203/4587/5117/4254/933/227/5137/180
6469/90223/10879/20949/1841201/101019/1807/10
3 11331
25/291273/2
317/471/459/249/241/47/4
449/829461/862307/81315/8
5967/120638/153929/40389/32545/24268/51849/12029/15
6801/80349/618353/1202391/101457/64891/30561/8527/30469/240
4 114641
23142624112
335/631137/2242/3107/21917/6
428/3111/21421219/6176185/282/37/2
51069/801316/1515289/602144/510993/244772/152803/20536/15967/240

For example, the first derivative with a third-order accuracy and the second derivative with a second-order accuracy are

${\displaystyle \displaystyle f'(x_{0})\approx \displaystyle {\frac {-{\frac {11}{6}}f(x_{0})+3f(x_{+1})-{\frac {3}{2}}f(x_{+2})+{\frac {1}{3}}f(x_{+3})}{h_{x}}}+O\left(h_{x}^{3}\right),}$
${\displaystyle \displaystyle f''(x_{0})\approx \displaystyle {\frac {2f(x_{0})-5f(x_{+1})+4f(x_{+2})-f(x_{+3})}{h_{x}^{2}}}+O\left(h_{x}^{2}\right),}$

while the corresponding backward approximations are given by

${\displaystyle \displaystyle f'(x_{0})\approx \displaystyle {\frac {{\frac {11}{6}}f(x_{0})-3f(x_{-1})+{\frac {3}{2}}f(x_{-2})-{\frac {1}{3}}f(x_{-3})}{h_{x}}}+O\left(h_{x}^{3}\right),}$
${\displaystyle \displaystyle f''(x_{0})\approx \displaystyle {\frac {2f(x_{0})-5f(x_{-1})+4f(x_{-2})-f(x_{-3})}{h_{x}^{2}}}+O\left(h_{x}^{2}\right),}$

## Backward finite difference

In general, to get the coefficients of the backward approximations, give all odd derivatives listed in the table the opposite sign, whereas for even derivatives the signs stay the same. The following table illustrates this[3]:

Derivative Accuracy 8 7 6 5 4 3 2 1 0
1 1       11
2      1/223/2
3     1/33/2311/6
2 1      121
2     1452
3 1     1331
2    3/271295/2
4 1    14641
2   2112426143

## Arbitrary stencil points

For a given arbitrary stencil points ${\displaystyle \displaystyle s}$ of length ${\displaystyle \displaystyle N}$ with the order of derivatives ${\displaystyle \displaystyle d, the finite difference coefficients can be obtained by solving the linear equations [4]

${\displaystyle {\begin{pmatrix}s_{1}^{0}&\cdots &s_{N}^{0}\\\vdots &\ddots &\vdots \\s_{1}^{N-1}&\cdots &s_{N}^{N-1}\end{pmatrix}}{\begin{pmatrix}a_{1}\\\vdots \\a_{N}\end{pmatrix}}=d!{\begin{pmatrix}\delta _{0,d}\\\vdots \\\delta _{i,d}\\\vdots \\\delta _{N-1,d}\end{pmatrix}},}$

where the ${\displaystyle \delta _{i,j}}$ are the Kronecker delta.

Example, for ${\displaystyle s=[-3,-2,-1,0,1]}$, order of differentiation ${\displaystyle d=4}$:

${\displaystyle {\begin{pmatrix}a_{1}\\a_{2}\\a_{3}\\a_{4}\\a_{5}\end{pmatrix}}={\begin{pmatrix}1&1&1&1&1\\-3&-2&-1&0&1\\9&4&1&0&1\\-27&-8&-1&0&1\\81&16&1&0&1\\\end{pmatrix}}^{-1}{\begin{pmatrix}0\\0\\0\\0\\24\end{pmatrix}}={\begin{pmatrix}1\\-4\\6\\-4\\1\end{pmatrix}}.}$

The order of accuracy of the approximation takes the usual form ${\displaystyle O\left(h^{(N-d)}\right)}$.