Computes the numerical Jacobian of functions or the symbolic Jacobian of characters in arbitrary orthogonal coordinate systems.

jacobian(
f,
var,
params = list(),
coordinates = "cartesian",
accuracy = 4,
stepsize = NULL
)

f %jacobian% var

## Arguments

f array of characters or a function returning a numeric array. vector giving the variable names with respect to which the derivatives are to be computed and/or the point where the derivatives are to be evaluated. See derivative. list of additional parameters passed to f. coordinate system to use. One of: cartesian, polar, spherical, cylindrical, parabolic, parabolic-cylindrical or a vector of scale factors for each varibale. degree of accuracy for numerical derivatives. finite differences stepsize for numerical derivatives. It is based on the precision of the machine by default.

## Value

array.

## Details

The function is basically a wrapper for gradient with drop=FALSE.

## Functions

• %jacobian%: binary operator with default parameters.

Guidotti, E. (2020). "calculus: High dimensional numerical and symbolic calculus in R". https://arxiv.org/abs/2101.00086

Other differential operators: curl(), derivative(), divergence(), gradient(), hessian(), laplacian()

## Examples

### symbolic Jacobian
jacobian("x*y*z", var = c("x", "y", "z"))
#>      [,1]    [,2]    [,3]
#> [1,] "y * z" "x * z" "x * y"
### numerical Jacobian in (x=1, y=2, z=3)
f <- function(x, y, z) x*y*z
jacobian(f = f, var = c(x=1, y=2, z=3))
#>      [,1] [,2] [,3]
#> [1,]    6    3    2
### vectorized interface
f <- function(x) x*x*x
jacobian(f = f, var = c(1, 2, 3))
#>      [,1] [,2] [,3]
#> [1,]    6    3    2
### symbolic vector-valued functions
f <- c("y*sin(x)", "x*cos(y)")
jacobian(f = f, var = c("x","y"))
#>      [,1]         [,2]
#> [1,] "y * cos(x)" "sin(x)"
#> [2,] "cos(y)"     "-(x * sin(y))"
### numerical vector-valued functions
f <- function(x) c(sum(x), prod(x))
jacobian(f = f, var = c(0,0,0))
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    0    0    0
### binary operator
"x*y^2" %jacobian% c(x=1, y=3)
#>      [,1] [,2]
#> [1,]    9    6