jacobian(f, x, h.eps=.Machine$double.eps^(1/3), ...)
m
functions of n
variables.n
.h
in the derivative formula.m
-by-n
matrix J
where the entry J[j, i]
is $\frac{\partial f_j}{\partial x_i}$, i.e. the derivatives of function
$f_j$ line up in row $i$ for $x_1, \ldots, x_n$.gradient
## Example function from Quarteroni & Saleri
f <- function(x) c(x[1]^2 + x[2]^2 - 1, sin(pi*x[1]/2) + x[2]^3)
jf <- function(x)
matrix( c(2*x[1], pi/2 * cos(pi*x[1]/2), 2*x[2], 3*x[2]^2), 2, 2)
all.equal(jf(c(1,1)), jacobian(f, c(1,1)))
# TRUE
Run the code above in your browser using DataLab