derivative() takes the first derivative of a single-variable function by central difference;
gradient() and hessian() take the gradient and the Hessian matrix of a function of a
parameter vector. All three are the ported Numerics NumericalDerivative routines.
Arguments
- f
for
derivative(), a function taking one number and returning one number; forgradient()andhessian(), a function taking a numeric vector and returning one number.- x
the point to differentiate at: one number for
derivative(), a numeric vector forgradient()andhessian().- step_size
the finite-difference step for
derivative().NULL, the default, leaves the ported routine's own step selection in force, as does any value at or below zero: the adaptive stepeps^(1/2) * (1 + |x|).
Value
derivative() returns a single number, gradient() a numeric vector the length of
x, and hessian() a square symmetric matrix.