# generateMATLABFunction

Generate MATLAB functions that evaluate the state and output functions, and their Jacobians, of a nonlinear grey-box or neural state-space model

*Since R2022b*

## Syntax

## Description

This function generates evaluation functions for the state, output, and Jacobians of a nonlinear grey-box model or a neural state-space model without autoencoder. You can use these functions to simulate the neural state-space or nonlinear grey-box system and to generate C/C++ code for deployment purposes, for applications such as nonlinear state estimation and model predictive control.

For a nonlinear grey-box model, if the file defining the model structure is a MEX file,
you cannot generate the evaluation function for the Jacobians of the state and output
functions. For information on nonlinear grey-box models, see `idnlgrey`

.

For a neural state-space model, to properly execute, the generated functions require the
Deep Learning Toolbox™ and the data files that store network information, which are also generated in
the process. To generate C/C++ code, the state and output networks of the neural state-space
model should be multi-layer perceptron (MLP) networks created using `createMLPNetwork`

with `tanh`

, `sigmoid`

, or `relu`

as the
activation function. For more information on the state and output functions of a neural
state-space object, see the corresponding properties of `idNeuralStateSpace`

.

For more information on Nonlinear MPC design, see Nonlinear MPC (Model Predictive Control Toolbox).

`generateMATLABFunction(`

generates, in the current folder, two MATLAB functions that calculate the state of
`sys`

,`stateFcnName`

)`sys`

and its Jacobians, respectively. The second argument is the
desired name of the state function. The state Jacobians function has the same name with the
suffix `Jacobian`

attached at the end. If `stateFcnName`

is empty, no state function or data file is generated.

`generateMATLABFunction(`

also specifies the name of the output function as a third argument. The output Jacobians
function has the same name with the suffix `sys`

,`stateFcnName`

,`outputFcnName`

)`Jacobian`

attached at the end.
If `outFcnName`

is empty, no output function or data file is generated.

**Note**

When a neural state-space object has a number of outputs equal to its number of
states, the generated output returns only the states. Therefore its Jacobian with
respect to the state (the *C* matrix) is an identity and its Jacobian
with respect to the input (the *D* matrix) is zero.

When a neural state-space object has a number of outputs greater than its number of
states, the generated output function only contains the non-trivial outputs, that is the
ones related to *y _{2}*(

*t*) =

*H*(

*t*,

*x*,

*u*). In other words, the generated function is only based on the second network in the

`OutputNetwork`

property of the object. For more
information, see `idNeuralStateSpace`

.

## Examples

## Input Arguments

## Version History

**Introduced in R2022b**

## See Also

### Objects

`idNeuralStateSpace`

|`nssTrainingADAM`

|`nssTrainingSGDM`

|`nssTrainingRMSProp`

|`nssTrainingLBFGS`

|`idss`

|`idnlgrey`

### Functions

`createMLPNetwork`

|`nssTrainingOptions`

|`nlssest`

|`idNeuralStateSpace/evaluate`

|`idNeuralStateSpace/linearize`

|`nlgreyest`

|`sim`