R: Functions for creating Gradient and Hessian matrices by...
numDerivs
R Documentation
Functions for creating Gradient and Hessian matrices by numerical differentiation (Richardson's method) of the partial derivatives
Description
These two functions create Gradient and Hessian matrices by Richardson's central finite difference method of the partial derivatives for any expression.
The two functions are modified versions of the genD function in the 'numDeriv' package, but a bit more easy to handle because they use expressions and the function's x value must not be defined as splitted scalar values x[1], x[2], ... in the body of the function.
Author(s)
Andrej-Nikolai Spiess
Examples
## Check for equality of symbolic
## and numerical derivatives.
EXPR <- expression(2^x + sin(2 * y) - cos(z))
x <- 5
y <- 10
z <- 20
symGRAD <- evalDerivs(makeGrad(EXPR))
numGRAD <- numGrad(EXPR)
all.equal(symGRAD, numGRAD)
symHESS <- evalDerivs(makeHess(EXPR))
numHESS <- numHess(EXPR)
all.equal(symHESS, numHESS)