Forward and centered finite difference give same error plot: why

error-propagationfinite differencesnumerical methodstruncation error

Let us consider the following standard approximations of the first derivative of a function

$$FD = \frac{f(x+h)-f(x)}{h}$$

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

The first is first order accurate, while the second it second order accurate.

Consider now $f=\sin(x)$ and $x =2\pi$. If we plot in loglog scale the error as a function of the stepsize $h$, we obtain the following graph, where it appears that the accuracy is the same.

error plot


My attempt to explain it

I look at the truncation error for the forward derivative:

$$\tau_1 = f''(x) \frac{h}{2} + f^{(3)}(x) \frac{h^2}{6} + O(h^3)$$

Looking at the plot, I would expect that the first term of the truncation error is $0$. So, I note that $f''(x)=-\sin(x)$, and for $x \approx 2\pi$ it is almost $0$. Therefore the leading error term is $-\cos(x) \frac{h^2}{2}$, which should motivate the second order accuracy.

Is it correct ?

Best Answer

This particular case is simply because the approximations themselves are (modulo floating point error) exactly the same for the same value of $h$:

$$\frac{\sin(2\pi+h)-\sin(2\pi)}{h}=\frac{\sin(2\pi+h)}{h}$$

whereas

$$\frac{\sin(2\pi+h)-\sin(2\pi-h)}{2h}=\frac{2\sin(2\pi+h)}{2h}=\frac{\sin(2\pi+h)}{h}$$

because of the fact that $\sin$ is an odd function when reflected through $2\pi$. Numerically this won't be exactly true but it will be close enough that they'll be indistinguishable except maybe for extremely small $h$.