What is the best method for 1D numeric differentiation? Something as glorious as Gaussian quadrature for numeric integration.


Maybe differential quadrature is such a method? What is its accuracy?


I'm well aware that it is really easy to have symbolic differentiation in the program (automatic differentiation or truly symbolic algorithm). However to use such methods it is necessary to rewrite all functions to be differentiated. Thus one can't differentiate functions imported from libraries.


I need differentiation almost with the machine precision.



Numerical Differentiation. What is the best method?
If your function is badly behaved (e.g. noisy, very oscillatory), no method will perform properly (differentiation is numerically very *unstable*). That being said, for "nice functions", I have good experience with polynomial (Richardson) extrapolation methods. [This paper](http://dx.doi.org/10.1007/BF02166671) and [this paper](http://dx.doi.org/10.1007/BF01933664) give hints on how you might write your own implementation. I will note that this is the method implemented in the [NAG numerical libraries](http://nag.co.uk/numeric/numerical_libraries.asp) (with of course a few wrinkles of their own).


There are two possible alternatives if for some reason you don't want to use Richardsonian methods. One is to use Cauchy's differentiation formula:


$$f^\prime(x)=\frac1{2\pi i}\oint\_\gamma \frac{f(t)}{(t-x)^2}\mathrm dt$$


where it is up to you to choose a suitable counterclockwise contour $\gamma$ (a circle is customary); the other is to use the ["Lanczos derivative"](http://www.jstor.org/pss/2589707):


$$f^\prime(x)=\lim\_{h\to 0}\frac{3}{2h^3}\int\_{-h}^h t\;f(x+t)\mathrm dt$$


where you either will have to experiment with an appropriate step size $h$, or use some extrapolative procedure.


You will have to experiment with your computing environment to choose.


