Function diff3

Calculate the derivative of a function using a three-point formula, a.k.a. a central difference formula.

real diff3(Func) (
  scope Func f,
  real x,
  real scale = 1.00000
);

The function is evaluated twice, at points just below and just above x.

Parameters

NameDescription
f The function to differentiate.
x The point at which to take the derivative.
scale A characteristic scale for f.

Returns

An approximation to the derivative of f at the point x. The relative error in the result is at best on the order of (real.epsilon)^(2/3), roughly three orders of magnitude more accurate than diff2().