Writing S-Functions Previous page   Next Page

Continuous Derivatives Pane

If the S-function has continuous states, use the Continuous Derivatives pane to enter code required to compute the state derivatives.

Enter code to compute the derivatives of the S-function's continuous states in the Code for the mdlDerivatives function field on this pane. When generating code, the S-Function Builder takes the code in this pane and inserts it in a wrapper function of the form

where sfun is the name of the S-function. The S-Function Builder inserts a call to this wrapper function in the mdlDerivatives callback method that it generates for the S-function. Simulink calls the mdlDerivatives method at the end of each time step to obtain the derivatives of the S-function's continuous states (see How Simulink Interacts with C S-Functions). The Simulink solver numerically integrates the derivatives to determine the continuous states at the next time step. At the next time step, Simulink passes the updated states back to the S-function's mdlOutputs method (see Outputs Pane).

The generated S-function's mdlDerivatives callback method passes the following arguments to the derivatives wrapper function:

The dx argument is a pointer to an array whose width is the same as the number of continuous derivatives specified on the Initialization pane. Your code should use this array to return the values of the derivatives that it computes. See mdlOutputs for the meanings and usage of the other arguments. The arguments allow your code to compute derivatives as a function of the S-function's inputs, outputs, and, optionally, parameters. Your code can invoke external functions declared on the Libraries pane.


Previous page  Outputs Pane Discrete Update Pane Next page

© 1994-2005 The MathWorks, Inc.