# Approximation of first derivative?

Find the best approximation to the first derivative of $f(x)$ based on the values of $f(x), f(x+h), f(x+2h)$. What is the accuracy of this approximation?

I was thinking of using a central difference approximation (because it is a 2nd order approximation) but I am unsure if that is correct.

-
Care to accept an answer? –  Did Nov 13 '11 at 10:17

Personally I would use $f'(x) \approx \dfrac{f(x+h)-f(x)}{h}$ for small $h$ but that may be closer to $f'(x+\frac{h}{2})$.

So if you have a reasonable approximation to both $f'(x+\frac{3h}{2})$ and $f'(x+\frac{h}{2})$ and if you think you function is fairly smooth (in the sense of an almost constant second derivative in the range $[x,x+2h]$) then you might reduce the earlier estimate by half the difference between those two, giving $$f'(x) \approx f'(x+\tfrac{h}{2}) - \frac{1}{2}\left(f'(x+\tfrac{3h}{2}) -f'(x+\tfrac{h}{2})\right)$$ and $$\frac{f(x+h)-f(x)}{h} - \frac{1}{2}\left(\tfrac{f(x+2h)-f(x+h)}{h} -\tfrac{f(x+h)-f(x)}{h}\right) = \frac{4f(x+h)-3f(x)- f(x+2h)}{2h}.$$

In fact this is the only estimate which gives correct results for quadratic functions and any $h$.

-
One could also derive the last result by performing Richardson extrapolation on the $2h$ and $h$ approximations... –  Ｊ. Ｍ. Oct 15 '11 at 0:35

From the Taylor series, $f(x+h) = f(x) + h f'(x) + h^2 f''(x)/2 +O(h^3)$ and $f(x-h) = f(x) - hf'(x) + h^2 f''(x)/2+O(h^3)$.

The only combination which gets rid of the $f''(x)$ term is $\frac{f(x+h)-f(x-h)}{2h} = f'(x) + O(h^2)$.

-
I talked about that here... –  Ｊ. Ｍ. Oct 16 '11 at 2:58

Here's a slight elaboration of my comment to Henry's answer: consider the series expansion

$$\frac{f(x+h)-f(x)}{h}=f^\prime(x)+\frac{f^{\prime\prime}(x)}{2}h+\frac{f^{(3)}(x)}{6}h^2+\cdots$$

From this, we get the double-step expansion

$$\frac{f(x+2h)-f(x)}{2h}=f^\prime(x)+f^{\prime\prime}(x)h+\frac{2f^{(3)}(x)}{3}h^2+\cdots$$

Richardson extrapolation here consists of finding a linear combination of the two previous expansions that knocks out the $h$ term; we find that

$$2\frac{f(x+h)-f(x)}{h}-\frac{f(x+2h)-f(x)}{2h}=f^\prime(x)-\frac{f^{(3)}(x)}{3}h^2+\cdots$$

and the left-hand side, after simplification, is precisely the last expression Henry obtained.

-