TITLE: Numerical Differentiation. What is the best method?
QUESTION [10 upvotes]: 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.

REPLY [3 votes]: Complex step differentiation (CSD) is well known as an efficient numerical differentiation method:
$$f^\prime(x)=\mathrm{Im}\frac{f(x+\mathrm{i}h)}{h}+O(h^2),\quad\mathrm{i}:=\sqrt{-1}.$$
This method requires the function to be analytic (differentiable as a complex function).
We cannot apply this method to higher order derivatives, but since this method does not use differences it is useful to avoid subtractive cancellation (loss of significance caused when we try to subtract similar numbers). For the derivation and implementations, check the article on SIAM News and the post on Mathworks Blog.
A noteworthy alternative to CSD is the approach by dual numbers. Dual numbers are defined by:
$$x=a+b\epsilon,\quad a,b\in\mathbb{R},\quad\epsilon^2=0.$$
By using Taylor expansion and dual numbers, we obtain
$$f(a+b\epsilon)=f(a)+bf^\prime(a)\epsilon\quad(\because\epsilon^2=0).$$
Hence we can obtain the derivative by dual numbers.