cjacobian
Jacobian of a multivariate, vector-valued function using the central difference approximation.
Back to Numerical Differentiation Toolbox Contents.
Contents
Syntax
J = cjacobian(f,x0) J = cjacobian(f,x0,h)
Description
J = cjacobian(f,x0) numerically evaluates the Jacobian of with respect to at using the central difference approximation with a default relative step size of , where is the machine zero.
J = cjacobian(f,x0,h) numerically evaluates the Jacobian of with respect to at using the central difference approximation with a user-specified relative step size .
Input/Output Parameters
Variable | Symbol | Description | Format | |
Input | f | multivariate, vector-valued function () | 1×1 function_handle |
|
x0 | evaluation point | n×1 double |
||
h | (OPTIONAL) relative step size (defaults to $h=\varepsilon^{1/3}$) | 1×1 double |
||
Output | J | Jacobian of with respect to , evaluated at | m×n double |
Note
- This function requires evaluations of .
Example
Approximate the Jacobian of
at using the cjacobian function, and compare the result to the true result of
Approximating the Jacobian,
f = @(x) [x(1);5*x(3);4*x(2)^2-2*x(3);x(3)*sin(x(1))]; x0 = [5;6;7]; J = cjacobian(f,x0)
J = 1.0000 0 0 0 0 5.0000 0 48.0000 -2.0000 1.9856 0 -0.9589
Calculating the error,
error = J-[1,0,0;0,0,5;0,48,-2;7*cos(5),0,sin(5)]
error = 1.0e-09 * -0.0009 0 0 0 0 -0.0289 0 0.1248 -0.0471 -0.4423 0 0.0087
NOTE: The function and its corresponding Jacobian are from an example on Wikipedia.