Numerical Differentiation

numerical_differentiation.numerical_jacobian(fcn, x0, dx=1e-06, method=0, return_f0=False)[source]

Compute the numerical Jacobian matrix of a given function.

Parameters:

fcn: function handle

Takes an N-vector as input and return an M-vector.

x0: ndarray

An input N-vector.

dx: scalar

For small change in x0.

method: int or string

With following options:
  • {0, ‘forward’}: compute the Jacobian as (f(x0+dx)-f(x0))/dx.
  • 1, ‘central’ : compute the Jacobian as (f(x0+dx)-f(x0-dx))/2/dx.

return_f0: boolean

If set to true, also return fcn(x0).

Returns:

J : ndarray

The MxN Jacobian matrix.

f0 : ndarray

The function value at x0.

Examples

>>> J = numerical_jacobian(fcn, x0, ...)
>>> (J, f0) = numerical_jacobian(fcn, x0, ..., return_f0=True)