jacobian: Gradient of a Vector Valued Function

Description Usage Arguments Details Value See Also Examples

Description

Calculate the m by n numerical approximation of the gradient of a real m-vector valued function with n-vector argument.

Usage

1
2
3
4
5
    jacobian(func, x, method="Richardson", side=NULL, method.args=list(), ...) 

    ## Default S3 method:
jacobian(func, x, method="Richardson", side=NULL,
       method.args=list(), ...)

Arguments

func

a function with a real (vector) result.

x

a real or real vector argument to func, indicating the point at which the gradient is to be calculated.

method

one of "Richardson", "simple", or "complex" indicating the method to use for the approximation.

method.args

arguments passed to method. See grad. (Arguments not specified remain with their default values.)

...

any additional arguments passed to func. WARNING: None of these should have names matching other arguments of this function.

side

an indication of whether one-sided derivatives should be attempted (see details in function grad).

Details

For f:R^n -> R^m calculate the m x n Jacobian dy/dx. The function jacobian calculates a numerical approximation of the first derivative of func at the point x. Any additional arguments in ... are also passed to func, but the gradient is not calculated with respect to these additional arguments.

If method is "Richardson", the calculation is done by Richardson's extrapolation. See link{grad} for more details. For this method method.args=list(eps=1e-4, d=0.0001, zero.tol=sqrt(.Machine$double.eps/7e-7), r=4, v=2, show.details=FALSE) is set as the default.

If method is "simple", the calculation is done using a simple epsilon difference. For method "simple" method.args=list(eps=1e-4) is the default. Only eps is used by this method.

If method is "complex", the calculation is done using the complex step derivative approach. See addition comments in grad before choosing this method. For method "complex", method.args is ignored. The algorithm uses an eps of .Machine$double.eps which cannot (and should not) be modified.

Value

A real m by n matrix.

See Also

grad, hessian, numericDeriv

Examples

1
2
3
4
   func2 <- function(x) c(sin(x), cos(x))
   x <- (0:1)*2*pi
   jacobian(func2, x)
   jacobian(func2, x, "complex")

Example output

     [,1] [,2]
[1,]    1    0
[2,]    0    1
[3,]    0    0
[4,]    0    0
     [,1]         [,2]
[1,]    1 0.000000e+00
[2,]    0 1.000000e+00
[3,]    0 0.000000e+00
[4,]    0 2.449294e-16

numDeriv documentation built on June 6, 2019, 5:07 p.m.