Getting Started with Model Simulation and Analysis

System modeling functionality is included in the Wolfram Language, allowing simulation and analysis of real-world phenomena in many domains.

The full Wolfram SystemModeler product also includes dedicated graphical user interfaces for model creation, exploration, simulation and analysis.

This tutorial gives an introduction to the functionality included in the Wolfram Language.

Explore Examples

SystemModeler comes with bundled examples from many domains and of varying complexity. All the bundled examples can be explored and simulated using the SystemModelExamples command. Evaluate the cell below to create the interactive example browser.

In[1]:=
Click for copyable input
Out[1]=
Click for copyable input

It is also possible to list all example models.

In[9]:=
Click for copyable input
Out[9]//Shallow=

Other sources of examples and models include:

Model Representation

System models in the Wolfram Language are represented with a SystemModel. Models are available either from other functions like the SystemModelExamples above or referring to them by their name as a string.

In[10]:=
Click for copyable input
Out[10]=

The resulting object can be copy-pasted, used in inputs to other functions and queried for properties.

In[11]:=
Click for copyable input
Out[11]=

Simulation

SystemModelSimulate runs a simulation of a model created in the Model Center and returns a SystemModelSimulationData object. SystemModelPlot is used to visualize results from that simulation.

SystemModelSimulate[model]simulate the model
SystemModelSimulationData[]object containing simulation results
SystemModelPlot[sd,"MyPlot"]show stored plot "MyPlot" from the SystemModelSimulationData sd
SystemModelPlot[sd,{"v1",}]plot variables vi

Basic system model simulation functions.

Basic Simulation and Plotting

To simulate a model, use the command SystemModelSimulate with the model as the argument.

In[12]:=
Click for copyable input
Out[12]=

The output from SystemModelSimulate is a SystemModelSimulationData object. This object can be used in SystemModelPlot to plot variables from the simulation. For many example models, there are stored plots defined by the model creator. These can be listed using the "PlotNames" property of the simulation result.

In[13]:=
Click for copyable input
Out[13]=

Such a plot can easily be shown in SystemModelPlot.

In[14]:=
Click for copyable input
Out[14]=

Simulation Data

The simulation result object also has a number of properties.

In[8]:=
Click for copyable input
Out[8]=

Take a look at the variable names in the simulation.

In[9]:=
Click for copyable input
Out[9]=

Plot two variables using SystemModelPlot.

In[10]:=
Click for copyable input
Out[10]=

Retrieve the value of the variables "signalVoltage1.i" and "EMF1.i" at time 2.

In[12]:=
Click for copyable input
Out[12]=

Parameter Changes

Simulate again, changing two parameters using "ParameterValues" and compare a result variable between the simulations.

In[13]:=
Click for copyable input
In[14]:=
Click for copyable input
In[15]:=
Click for copyable input
Out[15]=

Parameter Sweeps

Multiple simulations for a number of values of a parameter are automatically done in parallel. Simulate a bouncing ball with different amounts of bounciness "e".

In[16]:=
Click for copyable input
Out[16]=

Plot the height of the balls over time.

In[17]:=
Click for copyable input
Out[17]=

Custom Plots

By retrieving the simulation results as data, results can be visualized and analyzed in many waysfor example, by plotting the results from a Chua circuit on a ParametricPlot.

In[18]:=
Click for copyable input
In[19]:=
Click for copyable input

Pick out the variables "C1.v" and "C2.v".

In[20]:=
Click for copyable input
In[21]:=
Click for copyable input
Out[21]=

A Lorenz attractor makes for a beautiful simulation result with ParametricPlot3D.

In[22]:=
Click for copyable input
In[23]:=
Click for copyable input
In[24]:=
Click for copyable input
Out[24]=

Model Data

In addition to driving simulations of models from the Wolfram Language, it is also possible to work with the model more directly. SystemModel is used to retrieve information about models, and FindSystemModelEquilibrium and SystemModelLinearize are used to obtain equilibrium points and linear state-space representations.

SystemModel[model,]retrieve information about model
FindSystemModelEquilibrium[model]find equilibrium points for model
SystemModelLinearize[model]get a linear state-space representation of model

System modeling functions.

Equations from Model

Retrieve information about a model with SystemModel. First, get an overview of the model information.

In[27]:=
Click for copyable input
Out[27]=

Get the system equations depending on the time variable t.

In[29]:=
Click for copyable input
Out[29]=

Find a point where all derivatives are zero, also called an equilibrium point.

In[35]:=
Click for copyable input

There are a large number of properties of SystemModel that can be used to get information about the model.

In[2]:=
Click for copyable input
Out[2]=

Equilibrium Points and Linear Representation

Use FindSystemModelEquilibrium to find an equilibrium point for a model of a mixing tank.

In[33]:=
Click for copyable input
Out[33]=

The function SystemModelLinearize gives a linear state-space representation of a model at an equilibrium point. The result is a Wolfram Language StateSpaceModel.

In[34]:=
Click for copyable input
Out[34]=

The control functionality in the Wolfram Language can be used to further work with this representation. Design a controller using pole placement and show the output response to a unit step.

In[35]:=
Click for copyable input
In[38]:=
Click for copyable input
Out[38]=