Getting Started with Model Simulation and Analysis
Wolfram SystemModeler 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.
To use functionality from Wolfram SystemModeler Link, load the package:
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 WSMExamples command. Evaluate the cell below to create the interactive example browser.
It is also possible to list the names of all example models.
Simulation
WSMSimulate runs a simulation of a model created in the Model Center and returns a WSMSimulationData object. WSMPlot is used to visualize results from that simulation.
WSMSimulate["mmodel"] | simulate the model "mmodel" |
WSMSimulationData[…] | object containing simulation results |
WSMPlot[sd,"MyPlot"] | show stored plot "MyPlot" from the WSMSimulationData sd |
WSMPlot[sd,{"v1",…}] | plot variables vi |
Basic SystemModeler simulation functions.
Basic Simulation and Plotting
To simulate a model, use the command WSMSimulate with the model name as the argument.
The output from WSMSimulate is a WSMSimulationData object. This object can be used in WSMPlot 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.
Such a plot can easily be shown in WSMPlot.
Simulation Data
The simulation result object also has a number of properties.
Take a look at the variable names in the simulation.
Plot two variables using WSMPlot.
Variable names in models and simulations can be referred to using either the formatted DotName seen above, or using strings. These are equivalent.
Retrieve the value of the variables "signalVoltage1.i" and "EMF1.i" at time 2.
Parameter Changes
Simulate again, changing two parameters using the option WSMParameterValues and compare a result variable between the simulations.
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".
Plot the height of the balls over time.
Custom Plots
By retrieving the simulation results as data, results can be visualized and analyzed in many ways—for example, by plotting the results from a Chua circuit on a ParametricPlot.
Pick out the variables "C1.v" and "C2.v".
A Lorenz attractor makes for a beautiful simulation result with ParametricPlot3D.
Model Data
In addition to driving simulations of models from the Wolfram Language, it is also possible to work with the model more directly. WSMModelData is used to retrieve information about models, and WSMFindEquilibrium and WSMLinearize are used to obtain equilibrium points and linear state-space representations.
WSMModelData["mmodel",…] | retrieve information about "mmodel" |
WSMFindEquilibrium["mmodel"] | find equilibrium points for "mmodel" |
WSMLinearize["mmodel"] | get a linear state-space representation of "mmodel" |
SystemModeler model functions.
Equations from Model
Retrieve information about a model with WSMModelData. First, get an overview of the model information.
Get the system equations depending on the time variable t.
Find a point where all derivatives are zero, also called an equilibrium point.
There are a large number of properties of WSMModelData that can be used to get information about the model.
Equilibrium Points and Linear Representation
Use WSMFindEquilibrium to find an equilibrium point for a model of a mixing tank.
The function WSMLinearize gives a linear state-space representation of a model at an equilibrium point. The result is a Wolfram Language StateSpaceModel.
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.