### symbolic derivatives
derivative(f = "sin(x)", var = "x")
### numerical derivatives
f <- function(x) sin(x)
derivative(f = f, var = c(x=0))
### higher order derivatives
f <- function(x) sin(x)
derivative(f = f, var = c(x=0), order = 3)
### multivariate functions
## - derive once with respect to x
## - derive twice with respect to y
## - evaluate in x=0 and y=0
f <- function(x, y) y^2*sin(x)
derivative(f = f, var = c(x=0, y=0), order = c(1,2))
### vector-valued functions
## - derive each element twice with respect to each variable
## - evaluate in x=0 and y=0
f <- function(x, y) c(x^2, y^2)
derivative(f, var = c(x=0, y=0), order = 2)
### vectorized interface
f <- function(x) c(sum(x), prod(x))
derivative(f, var = c(0,0,0), order = 1)
Run the code above in your browser using DataLab