# numerical differentiation: where to put the results?

I have a parametric equation $r(t) = \left< 5\cos t, 5\sin t \right>$ from $t = 1$ to $t = 200$

I want to numerally compute the first derivative (velocity), and I am left with 199 data points only. Where should I put the first data point of the velocity if I use the definition $r'(t) = \displaystyle\frac{r(t+h) - r(t)}{h}$? Do I put it in the line $t = 1$ or in line $t=2$?

What happens if I use the central difference method? (For example: $r'(3) = \frac{r(4)-r(2)}{4-2}$, how will I deal with the endpoints?)

• Are you certain that "from $t = 1$ to $t = 200$" means $t$ only takes integer values? Commented Nov 6, 2017 at 7:47
• Did you mean from 1 to 200 degrees in a circle of 360 degrees? Commented Nov 6, 2017 at 8:37

You are right that the best choice among the simple difference quotients is the central difference quotient with error order 2. For the interval end, for instance the left, use $$\frac{f(t+h)-f(t)}{h}=f'(t)+\frac h2f''(t)+O(h^2)=f'(t)+\frac h2f''(t+h)+O(h^2) \\ =f'(t)+\frac h2\frac{f(t+2h)-2f(t+h)+f(t)}{h^2}+O(h^2)$$ so that $$f'(t)=\frac{-f(t+2h)+4f(t+h)-3f(t)}{2h}+O(h^2)$$ has also error order 2. Similarly for the right side, just replace $h$ by $-h$.
• This is a nice shortcut for the one sided approximation. I have always expanded $f(x+h)$ and $f(x+2h)$ and solved for the weights. Commented Nov 6, 2017 at 9:08
• Thanks for this. I forgot to ask about the case of $f''(x)$ (as an endpoint)