# generateJacobianFcn

Generate MATLAB Jacobian functions for extended Kalman filter using automatic differentiation

*Since R2023a*

## Syntax

## Description

generates the state transition Jacobian function for an extended Kalman filter (EKF) using
the automatic differentiation technique.`fcnStateJac`

= generateJacobianFcn(`obj`

,'state',`Us1,...,Usn`

)

This function generates two MATLAB^{®} function files in the current folder:

`stateTransitionJacobianFcn.m`

— The generated state transition Jacobian function`stateTransitionJacobianFcnAD.m`

— A helper function that uses automatic differentiation to generate the state transition Jacobian function

`fcnStateJac`

is a handle to an anonymous function that
calls `stateTransitionJacobianFcn.m`

using the input
`extendedKalmanFilter`

object (`obj`

), the additional
input arguments passed to the `predict`

function of
`obj`

(`Us1,...,Usn`

), and the constants used
internally to compute the state transition Jacobian.

To use this Jacobian in the EKF object, specify `fcnStateJac`

in the
`StateTransitionJacobianFcn`

property of the object. For
example:

obj.StateTransitionJacobianFcn = fcnStateJac;

generates the measurement Jacobian function for an extended Kalman filter (EKF) using the
automatic differentiation technique.`fcnMeasurementJac`

= generateJacobianFcn(`obj`

,'measurement',`Um1,...,Umn`

)

This function generates two MATLAB function files in the current folder:

`measurementJacobianFcn.m`

— The generated measurement Jacobian function`measurementJacobianFcnAD.m`

— A helper function that uses automatic differentiation to generate the measurement Jacobian function

`fcnMeasurementJac`

is a handle to an anonymous function
that calls `measurementJacobianFcn.m`

using the input
`extendedKalmanFilter`

object (`obj`

), the additional
input arguments passed to the `correct`

function of
`obj`

(`Um1,...,Umn`

), and the constants used
internally to compute the measurement Jacobian.

To use this Jacobian in the EKF object, specify `fcnMeasurementJac`

in the `MeasurementJacobianFcn`

property of the object. For
example:

obj.MeasurementJacobianFcn = fcnMeasurementJac;

`[___,`

also returns the constants used to compute the Jacobian function. You can return the
constants for either Jacobian function.`constants`

] = generateJacobianFcn(___)

## Examples

## Input Arguments

## Output Arguments

## Limitations

Automatic differentiation currently supports only a limited set of mathematical operations, which are described in Supported Operations for Optimization Variables and Expressions (Optimization Toolbox). If your original state transition or measurement function uses operations or functions that are not in the list, or has if-else statements or loops,

`generateJacobianFcn`

terminates with an error.To generate Jacobian functions, do not preallocate any optimization variable in the original function. For example, suppose you try to generate Jacobians from a function containing the following code.

This code results in the following error.dxdt = zeros(2,1); dxdt(1) = x(1)*x(2); dxdt(2) = x(1)/x(2);

Instead, use this code.Unable to perform assignment because value of type 'optim.problemdef.OptimizationExpression' is not convertible to 'double'.

dxdt = [x(1)*x(2); x(1)/x(2)];

Specifying the state transition and measurement functions in

`obj`

as files in the current folder or in a folder on the MATLAB path is recommended. While handles to local functions are supported for Jacobian function generation, they are not supported for generation of C/C++ deployment code. For more information on local functions, see Local Functions.

## Version History

**Introduced in R2023a**