# NOT RUN {
# derive f with respect to x
derivative(f = "sin(x)", var = "x")
# derive f with respect to x and evaluate in x = 0
derivative(f = "sin(x)", var = c("x" = 0))
# derive f twice with respect to x
derivative(f = "sin(x)", var = "x", order = 2)
# derive f once with respect to x, and twice with respect to y
derivative(f = "y^2*sin(x)", var = c("x","y"), order = c(1,2))
# compute the gradient of f with respect to (x,y)
derivative(f = "y*sin(x)", var = c("x","y"))
# compute the Jacobian of f with respect to (x,y)
f <- c("y*sin(x)", "x*cos(y)")
derivative(f = f, var = c("x","y"))
# compute the Hessian of f with respect to (x,y)
g <- derivative(f = "y^2*sin(x)", var = c("x","y"))
derivative(f = g, var = c("x","y"))
# compute the Jacobian of f with respect to (x,y) and evaluate in (0,0)
f1 <- function(x, y) y*sin(x)
f2 <- function(x, y) x*cos(y)
derivative(f = c(f1, f2), var = c("x"=0,"y"=0))
# }
Run the code above in your browser using DataLab