### Numerical differentiation: Difference formulas for the second derivative

### The 3-point central difference formula

We consider a 'neat' function \(f\) near a point \(x_0\). The second derivative \(f''\) is of course the derivative of the first derivative \(f'\). If you apply the 3-point central difference formula repeatedly, you can therefore find an approximation formula for the second derivative in \(x_0\) at a step size \(h\).

\[\begin{aligned} f''(x_0)&\approx \frac{f'(x_0+h)-f'(x_0-h)}{2h} \\ \\ &\approx\frac{\displaystyle\frac{f(x_0+2h)-f(x_0)}{2h}-\frac{f(x_0)-f(x_0-2h)}{2h}}{2h}\\ \\ &=\frac{f(x_0+2h)-2f(x_0)+f(x_0-2h)}{(2h)^2}\end{aligned}\]

But now you see that you need the function values in \(x_0-2h\), \(x_0\) and \(x_0+2h\). However, if you use imaginary points on \(x_0-\tfrac{1}{2}h\) and \(x_0+\tfrac{1}{2}h\), you end up with the following 3-point central difference formula for the second derivative:

Central 3-point difference formula for the second derivative \[ f''(x_0)\approx \frac{f(x_0+h)-2f(x_0)+f(x_0-h)}{h^2}\text{,}\quad\text{for a small value of }h\text.\]

A more formal derivation of the 3-point central difference formula for the second derivative provides more insight into the truncation error.

We look at two Taylor approximations around \(x_0\): \[\begin{aligned} f(x_0+h)=f(x_0)+f'(x_0)h+\tfrac{1}{2}f''(x_0)h^2+\tfrac{1}{6}f'''(x_0)h^3+ O(h^4)\\[3pt] f(x_0-h)=f(x_0)-f'(x_0)h+\tfrac{1}{2}f''(x_0)h^2-\tfrac{1}{6}f'''(x_0)h^3+ O(h^4)\end{aligned}\] When we add the two equations, we get: \[ f(x_0+h)+ f(x_0-h)=2f(x_0)h +f''(x_0)h^2 +O(h^4)\] Thus: \[\frac{f(x_0+h)-2f(x_0)+f(x_0-h)}{h^2}=f''(x_0)+ O(h^2)\] The truncation error of this 3-point central difference approximation is quadratic in \(h\).