diff2

Calculate the derivative of a function using a two-point formula, i.e. a forward- or backward-difference formula.

This method only evaluates the function once (in addition to the function value provided by the user), and is therefore the fastest way to compute a derivative. However, it is also the least accurate method, and should only be used if the function is very expensive to compute and you have already calculated f(x).

real
diff2
(
Func
)
(
scope Func f
,
real x
,
real fx
,
real scale = 1.0
)

Parameters

f Func

The function to differentiate.

x real

The point at which to take the derivative.

fx real

The function value at x, i.e. f(x)

scale real

A characteristic scale for f. When this is positive, the forward-difference formula is used, and when it is negative, the backward-difference formula is used.

Return Value

Type: real

An approximation to the derivative of f at the point x. The relative error in the result is at best on the order of sqrt(real.epsilon). Usually it is much higher.

Meta