fjacobian

Jacobian of a multivariate, vector-valued function using the forward difference approximation.

Back to Numerical Differentiation Toolbox Contents.

Contents

Syntax

J = fjacobian(f,x0)
J = fjacobian(f,x0,h)

Description

J = fjacobian(f,x0) numerically evaluates the Jacobian of $\mathbf{f}$ with respect to $\mathbf{x}$ at $\mathbf{x}=\mathbf{x}_{0}$ using the forward difference approximation with a default relative step size of $h=\sqrt{\varepsilon}$, where $\varepsilon$ is the machine zero.

J = fjacobian(f,x0,h) numerically evaluates the Jacobian of $\mathbf{f}$ with respect to $\mathbf{x}$ at $\mathbf{x}=\mathbf{x}_{0}$ using the forward difference approximation with a user-specified relative step size $h$.

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 ) 1×1
double
Output J Jacobian of with respect to , evaluated at m×n
double

Note

Example

Approximate the Jacobian of

$$\mathbf{f}(\mathbf{x})=\pmatrix{x_{1} \cr 5x_{3} \cr 4x_{2}^{2}-2x_{3} \cr x_{3}\sin{x_{1}}}$$

at $\mathbf{x}=\mathbf{x}_{0}=(5,6,7)^{T}$ using the fjacobian function, and compare the result to the true result of

$$\mathbf{J}(\mathbf{x}_{0})=\pmatrix{1 & 0 & 0 \cr 0 & 0 & 5 \cr 0 & 48
& -2 \cr 7\cos{(5)} & 0 & \sin{(5)}}$$

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 = fjacobian(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-06 *

         0         0         0
         0         0         0
         0    0.5450         0
    0.3102         0    0.0035

NOTE: The function and its corresponding Jacobian are from an example on Wikipedia.

See also

cjacobian | ijacobian