Central Difference to Approximate f'(x)

Solution 1:

To give the overall idea without completely solving your homework, change to the second derivative and another function.

I take it that the approximation formula has to make the best of all 5 function values. At first, forget about the specific form of $f$, only use that it is sufficiently often continuously differentiable. Then by combining Taylor series the normal central difference formula has error terms $$ D_2(x,h)=\frac{f(x-h)-2f(x)+f(x+h)}{h^2}=f''(x)+\frac{2f^{(4)}(x)}{4!}h^2+\frac{2f^{(6)}(x)}{6!}h^4+\frac{2f^{(8)}(x)}{8!}h^6+... $$ Now replace $h$ by $2h$ in that formula$$ D_2(x,2h)=\frac{f(x-2h)-2f(x)+f(x+2h)}{4h^2}=f''(x)+\frac{2\cdot 2^2f^{(4)}(x)}{4!}h^2+\frac{2⋅2^4f^{(6)}(x)}{6!}h^4+\frac{2⋅2^6f^{(8)}(x)}{8!}h^6+... $$ Now it is easy to see what combination of both formulas will eliminate the leading quadratic error term $$ 4D_2(x,h)-D_2(x,2h)=3f''(x)-\frac{2⋅(2^4-4)f^{(6)}(x)}{6!}h^4+O(h^6) $$ giving the formula \begin{align} D_4(x,h)=\frac{4D_2(x,h)-D_2(x,2h)}3 &=\frac{-f(x-2h)+16f(x-h)-30f(x)+16f(x+h)-f(x+2h)}{12h^2}\\ &=f''(x)-\frac{f^{(6)}(x)}{90}h^4+O(h^6) \end{align}

For $f(x)=\sin(x)$ where we know $f''(x)=-\sin(x)=f^{(6)}(x)$, we can try to numerically confirm that picture

enter image description here

where the error is drawn together with the numerical error bound composed of bounds for the floating point evaluation and the leading error term $$ \frac{64|f(x)|\epsilon}{12h^2}+\frac{|f^{(6)}(x)|}{90}h^4 $$ where $ϵ\simeq 10^{-16}$ is the floating point machine constant. As to be expected from this formula, the error is minimal where the terms are equal, around $h\sim\sqrt[6]{500ϵ}\approx 0.006$.