Error from central difference seems large

58 Views Asked by At

for a function $f(x)=e^{2x}-\cos(2x)$,

at grid points $x \in {-0.3,-0.2,-0.1,0}$

I perform a central difference for the derivative at $x=-0.2$

$$\frac{df}{dx}=\frac{f(-0.1)-f(-0.3)}{2*(-0.1--0.3)}=0.28795$$ The derivative of this function (per mathematica) is $0.561803$ So the error is $$Abs[0.561803-0.28795]=0.273853$$

I have a formula for the upper bound of the error, and that formula is $$\frac{M^*\Delta x^2}{3!}=\frac{8*(-0.1--0.3)}{6}=0.0533333\\\text{Where }M^*=\text{Max}(f''(x)|x\in[-0.3,0])=f(0)=8$$

The issue is the error, $0.27$, is greater than the supposid error bound, $0.05$. When I graph this function with its central difference though, it looks correct.

Graph of f(x) and finite/central differences

Any idea why my derivatives are higher than the upper bound? The error does seem pretty high.

1

There are 1 best solutions below

2
On BEST ANSWER

The problem lies in your definition of $\Delta x$, remember that

$$ f'_{FD}(x) \approx \frac{f(x + \Delta x) - f(x - \Delta x)}{2\Delta x} $$

Taking $x = -0.2$ and $\Delta x = 0.1$ we get

$$ f'_{FD}(-0.2) \approx \frac{f(-0.1) - f(-0.3)}{2 \cdot 0.1} = 0.575941 \tag{1} $$

So the actual error is

$$ \epsilon = |f'_{FD}(-0.2) - f'(-0.2)|= 0.0141374 \tag{2} $$

Now, the prediction for the error is

$$ \epsilon_{\max} = \frac{|f^{(3)}(c)|\Delta^2 x}{6} \stackrel{c=-0.3}{=} 0.0148461 \tag{3} $$

You can indeed see that

$$ \epsilon < \epsilon_\max $$