The function of which to take the derivative.
The point at which to take the derivative.
A "characteristic scale" over which the function changes.
Stepsize is decreased by factor at each iteration.
Return when error is SAFE worse than the best so far.
References:
import mir.math.common; auto f(double x) { return exp(x) / (sin(x) - x ^^ 2); } auto d(double x) { return -(exp(x) * ((x - 2) * x - sin(x) + cos(x)))/(x^^2 - sin(x))^^2; } auto r = diff!f(1.0, 0.01); assert (approxEqual(r.value, d(1)));
Calculate the derivative of a function. This function uses Ridders' method of extrapolating the results of finite difference formulas for consecutively smaller step sizes, with an improved stopping criterion described in the Numerical Recipes books by Press et al.
This method gives a much higher degree of accuracy in the answer compared to a single finite difference calculation, but requires more function evaluations; typically 6 to 12. The maximum number of function evaluations is 24.