How to obtain (prove) 5-stencil formula for 2nd derivative?

For more familiar notation, I write e.g. $x\pm h$ instead of $x \pm dh$ as in your question.

Accounting for typos (please see @ChristianBlatter 's comment on your question), note that the Taylor expansions you wrote out imply the following:

$$16 f(x+h) + 16 f(x-h) = 32 f(x) + 16 h^2 f''(x)$$

and

$$f(x+2h) + f(x-2h) = 2f(x) + 4 h^2 f''(x).$$

Subtracting the second equation from the first yields

$$16 f(x+h) + 16 f(x-h) - f(x+2h) - f(x-2h) = 30 f(x) - 12 h^2 f''(x),$$

which can be solved for $f''(x)$ by moving $30 f(x)$ to the other side and dividing by $12 h^2$. We get

$$f''(x) = \frac{16 f(x+h) + 16f(x-h) - 30 f(x) - f(x-2h) - f(x+2h)}{12 h^2},$$

which is perhaps that which you were looking for...


You are on the right track, but you need to take the Taylor series up to the term in $h^4$. Add the series for $f(x+h)$ to the one for $f(x-h)$, which cancels the terms in $h$ and $h^3$, to obtain an expression involving only even powers of $h$. Do the same for the series for $f(x+2h)$ and $f(x-2h)$ to get another expression involving $h^2$ and $h^4$. Now take $16$ times the first expression from the latter one to eliminate $h^4$, and rearrange algebraically to get the required result.

This method shows that the result is accurate up to the fourth order of Taylor approximation. You could get the same result by choosing suitable linear combinations of the second-order approximations, but that wouldn't demonstrate that the accuracy is any better than second-order.