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

My question seems pretty easy. Prove the correctness of the following approximation:

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

I rendered myself deeply saddened upon stumbling on this and being seemingly unable solve it by my own. I also failed to find proof anywhere online. Only final answer.

The way I tried to it is via pretty common Taylor series expansion:

$$f(x+h) = f(x) + f'(x)h+\frac{1}{2!}f''(x)h^2+\frac{1}{3!}f^{(3)}(x)h^3 + \frac{1}{n!}f^{(n)}(x)h^n\quad (1)$$

I cut it off after $f^{(3)}$.

I use this formula to get rest of the points to have 5-stencils, simply by substituting $h$ with $\{-h; 2h; -2h\}$ Thus I get:

$$f(x-h) = f(x) - f'(x)h+\frac{1}{2!}f''(x)h^2-\frac{1}{3!}f^{(3)}(x)h^3\quad (2)$$ $$f(x+2h) = f(x) + 2f'(x)h+\frac{4}{2!}f''(x)h^2+\frac{8}{3!}f^{(3)}(x)h^3\quad (3)$$ $$f(x-2h) = f(x) - 2f'(x)h+\frac{4}{2!}f''(x)h^2-\frac{8}{3!}f^{(3)}(x)h^3\quad (4)$$

When I use equations $(1)$ and $(2)$, and add them by sides, I can get the 3 point formula:

$$f(x+h) + f(x-h) = 2f(x) + f''(x)h^2\quad (5)$$

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

However when I try to do this with all the equations $(1)$-\$(4) I get:

$$f(x+h) + f(x-h) = 2f(x) + f''(x)h^2 \quad (6)$$
$f(x+2h) + f(x-2h) = 2f(x) +4f''(x)h^2\quad (7)$

Then I can try subtracting $(6)$ from $(7)$ and I get:

$$f(x+h) + f(x-h) - f(x+2h) - f(x-2h) = 3 f''(x)h^2\quad (8)$$

which gives

$$f''(x) = \frac{f(x+h) + f(x-h) - f(x+2h) - f(x-2h) } {3 h^2} \quad(9)$$

This is clearly different from what I am expecting. Also doing $(6)$+$(7)$ doesn't seem to yield correct coefficients, even though it preserves $f(x)$ term.

Could you point out flaw in the approach and provide correct reasoning or any materials. All I found were very general or final answers with no explicit transformations. I feel kinda stupid being unable to get it right but I can't spot the flaw.

-

Please check your first formula for typos: $dh$ for $h$, $16(x-dh)$ where presumably $16(x+h)$ is meant. – Christian Blatter Dec 20 '12 at 17:39
@ChristianBlatter Yes, sorry. h and dh mean exactly the same. Sorry for inconsistency. I edited the question to unifiy it. – luk32 Dec 20 '12 at 17:43
– Amzoti Dec 20 '12 at 17:57

## 2 Answers

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) = \dfrac{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...

-

Ha! I knew it was stupid-level easy. Thank you. However, why use such weights, and is the formula (9) wrong or less accurate ? It just looks like dropping in some weights to increace imporantce of points closer to the $x$. Am I right? – luk32 Dec 21 '12 at 5:00
@luk32: The question in your comment is answered by the last sentence of my answer. – John Bentin Dec 21 '12 at 9:56
@JohnBentin Yeah I got it after a while. Precisely after I read your answer for 3rd time and already had a morning coffe. Too bad I can't accept both answers but I upvoted yours too as it helped me understand the difference. Thank You ! – luk32 Dec 21 '12 at 9:59

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.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 38, "mathjax_display_tex": 10, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9615221619606018, "perplexity_flag": "middle"}