Second order approximation of first derivative gives odd results

1.1k Views Asked by At

Assume I want to find the second order approximation of the first derivative in 0 of a function $f(x)$ (not defined for $x<0$). I will use the formulation for the forward derivative:

$f'(0)\approx \frac{-3f(0)+4f(h)-f(2h)}{2h}$

where $h$ is the step in the regular grid I am using. Now assume that the values of the function are: $f(0)=0$, $f(h)=5$, $f(2h)=25$. The function is clearly monotonically increasing and the first derivative in 0 is expected to be positive but, from the formula above, I get a negative value.

What am I missing? Does the issue all lie in the error (that I neglected)?

3

There are 3 best solutions below

0
On

A difference quotient with three terms should be exact for quadratics. You can even use this fact to derive difference quotients. So, let's fit a quadratic to the points $\{(0,0),(h,5),(2h,25)\}$; we find that $$ f(x) = \frac{15 x^2}{2 h^2}-\frac{5 x}{2 h}. $$ It's easy enough to check that this quadratic passes through the desired points. It's also easy to check that $$ f'(0)=\frac{4 f(h)-f(2 h)-3 f(0)}{2 h}=-\frac{5}{2 h} $$ and, in particular, that the derivative is negative when $h>0$. In fact, it grows in absolute value as $h\searrow0$.

1
On

Try $$ f'(0)\approx \frac{(2-h)f(2h)-(4-4h)f(h) +(2-3h)f(0)}{2h^2}.$$

1
On

Using $f(x+h) =f(x)+hf'(x)+h^2f''(x)/2+O(h^3)$, we get

$\begin{array}\\ \dfrac{-3f(0)+4f(h)-f(2h)}{2h} &=\dfrac{-3f(0)+4(f(0)+hf'(0)+h^2f''(0)/2+O(h^3))-(f(0)+2hf'(0)+4h^2f''(0)/2+O(h^3))}{2h}\\ &=\dfrac{2hf'(0)-3h^2f''(0)/2+O(h^3)}{2h}\\ &=f'(0)-3hf''(0)/2+O(h^2)\\ \end{array} $

so the approximation goes in the opposite direction than $f''(0)$.