D(expr, namevec) deriv(expr, namevec, function.arg = NULL, tag = ".expr")
expr
| expression which should be derivated |
namevec
| character vector, giving the variable names with respect to which derivatives will be computed. |
function.arg
| ... ?? ... |
tag
| ... ?? ... |
D is modelled after its S pendant for taking simple symbolic
derivatives.
deriv is a generic function with a default and a
formula method. It returns a call for
computing the expr and its (partial) derivatives,
simultaneously. It uses so-called ``algorithmic
derivatives''.
Currently, deriv.formula just calls deriv.default after
extracting the expression to the right of ~.
D returns an expression and therefore can easily be iterated
for higher derivatives.
deriv returns a call object which becomes an
expression when evaluated once. Evaluation of the
latter expression returns the function values with a
".gradient" attribute containing the gradient matrix.
It's author, MM, has only got a vague idea and thinks that a help page is better than none.
nlm for numeric minimization which should make use of
derivatives.
## formula argument :
dx2x <- deriv(~ x^2, "x") ; dx2x
##- expression({
##- .value <- x^2
##- .grad <- array(0, c(length(.value), 1), list(NULL, c("x")))
##- .grad[, "x"] <- 2 * x
##- attr(.value, "gradient") <- .grad
##- .value
##- })
mode(dx2x)
x <- -1:2
eval(dx2x)
## Something `tougher':
trig.exp <- expression(sin(cos(x + y^2)))
( D.sc <- D(trig.exp, c("x", "y")) )
( dxy <- deriv(trig.exp, c("x", "y")) )
y <- 1
eval(dxy)
eval(D.sc)