Create Simscape Equations from MuPAD Expressions


MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

To convert a MuPAD notebook file to a MATLAB live script file, see convertMuPADNotebook. MATLAB live scripts support most MuPAD functionality, although there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Symbolic Math Toolbox™ lets you integrate symbolic computations into the Simscape™ modeling workflow by using the results of these computations in the Simscape equation section.

If you work in the MATLAB Live Editor, see Generate Simscape Equations from Symbolic Expressions. Working in the MATLAB Live Editor is recommended.

If you work in the MuPAD Notebook app, you can:

  • Assign the MuPAD expression to a variable, copy that variable from a notebook to the MATLAB workspace, and use simscapeEquation to generate the Simscape equation in the MATLAB Command Window.

  • Generate the Simscape equation from the MuPAD expression in a notebook.

In both cases, to use the generated equation, you must manually copy the equation and paste it to the equation section of the Simscape component file.

For example, follow these steps to generate a Simscape equation from the solution of the ordinary differential equation computed in the MuPAD Notebook app:

  1. Open a MuPAD notebook with the handle notebook_handle:

    notebook_handle = mupad;

  2. In this notebook, define the following equation:

    s:= ode(y'(t) = y(t)^2, y(t)):
  3. Decide whether you want to generate the Simscape equation in the MuPAD Notebook or in the MATLAB Command Window.

GenerateSimscape Equations in the MuPAD Notebook App

To generate the Simscape equation in the same notebook, use generate::Simscape. To display generated Simscape code on screen, use the print function. To remove quotes and expand special characters like line breaks and tabs, use the printing option Unquoted:

print(Unquoted, generate::Simscape(s))

This command returns the Simscape equation that you can copy and paste to the Simscape equation section:

  -y^2+y.der == 0.0;

Generate Simscape Equations in the MATLAB Command Window

To generate the Simscape equation in the MATLAB Command Window, follow these steps:

  1. Use getVar to copy variable s to the MATLAB workspace:

    s = getVar(notebook_handle, 's')

    Variable s and its value appear in the MATLAB workspace and in the MATLAB Command Window:

    s =
    ode(diff(y(t), t) - y(t)^2, y(t))
  2. Use simscapeEquation to generate the Simscape equation from s:


You can copy and paste the generated equation to the Simscape equation section. Do not copy the automatically generated variable ans and the equal sign that follows it.

ans =
s == (-y^2+y.der == 0.0);