Function Repository Resource:

SystemModelManipulate

Source Notebook

Manipulate parameters or initial values in plots of model simulation results

Contributed by: Wolfram MathCore

ResourceFunction["SystemModelManipulate"][model]

creates a Manipulate object from model showing the resulting plots of a simulation with controllers for parameters and initial values.

ResourceFunction["SystemModelManipulate"][model,{u}]

creates a control only for the top-level parameter or variable u.

ResourceFunction["SystemModelManipulate"][model,{u,umin,umax}]

allows the value for u to vary between umin and umax.

ResourceFunction["SystemModelManipulate"][model,{{u,uinit},umin,umax,}]

takes the initial value of u to be uinit.

ResourceFunction["SystemModelManipulate"][model,{u,{u1,u2,}}]

allows u to take on discrete values u1,u2,.

ResourceFunction["SystemModelManipulate"][model,{u,func}]

creates a control from the function func.

ResourceFunction["SystemModelManipulate"][model,{u,},{v,},]

provides controls to manipuate each u,v,.

Details and Options

The model can have the following forms:
SystemModel[]general system model
StateSpaceModel[]state-space model
TransferFunctionModel[]transfer function model
AffineStateSpaceModel[]affine state-space model
NonlinearStateSpaceModel[]nonlinear state-space model
DiscreteInputOutputModel[]discrete input-output model
ResourceFunction["SystemModelManipulate"] by default provides controls for top-level parameters and initial values of top-level variables.
For a SystemModel model, model["TopParameterNames"] and model["TopSystemVariables"] provide names for top-level parameters and variables in model.
ResourceFunction["SystemModelManipulate"][model] by default picks a range for the controls depending on its type, initial value and min or max values, if given in the model.
For a SystemModel model with stored control annotations, ResourceFunction["SystemModelManipulate"][model] reproduces them.
ResourceFunction["SystemModelManipulate"][model,{tmin,tmax},] simulates and plots from time tmin to time tmax.
ResourceFunction["SystemModelManipulate"][model] shows all the default plots specified in the model. "Plots" is accepted as a special value in ResourceFunction["SystemModelManipulate"][model,,{"Plots",},] to include a controller for switching the plots.
ResourceFunction["SystemModelManipulate"][model, {u,umin,umax,du}] allows the value for u to vary between umin and umax in steps du.
ResourceFunction["SystemModelManipulate"][model, {{u,uinit,ulbl},}] labels the controls for u with ulbl.
ResourceFunction["SystemModelManipulate"][model, {u,{u1lbl1,u2lbl2,}}] labels the controls values u1,u2, with labels lbl1,lbl2,
ResourceFunction["SystemModelManipulate"][,spec] uses Association spec to set inputs, or additional parameter or initial values:
"ParameterValues"{p1val1,}set parameter pi to value vali
"InitialValues"{v1val1,}set initial value of variable vi to vali
"Inputs"{in1fun1,}set input ini to value funi[t] at time t
If the parameters and variables have descriptions in the model, these are displayed with a Tooltip in their corresponding controllers.
ResourceFunction["SystemModelManipulate"] has the same options as SystemModelSimulate, SystemModelPlot and Manipulate, with the following additions and changes:
Appearance"Open"appearance of controls for real and integer values
ContinuousActionFalsewhether to update continuously when controls are changed
SynchronousInitializationFalsewhether to perform initialization synchronously
SynchronousUpdatingFalsewhether to update synchronously
Options such as ControlType and Appearance can be given separately for each variable, in the form {u,spec,opts}.
Available example models can be found using SystemModelExamples.

Examples

Basic Examples (3) 

Create a dynamic interface for a model simulation:

In[1]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/986c6990-5a44-4fb2-97e8-fc72bb6ea190"]
Out[1]=

Manipulate an initial value in a simulation:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/8054af49-c6ce-4037-9437-b1f9e1a116ce"]
Out[2]=

Specify the model by name and manipulate a specific parameter value in a simulation:

In[3]:=
ResourceFunction[
 "SystemModelManipulate"]["IndustryExamples.Other.BoostConverter", {"r1", 18, 24}]
Out[3]=

Scope (23) 

Models (5) 

Control initial values in an AffineStateSpaceModel:

In[4]:=
ResourceFunction["SystemModelManipulate"][ AffineStateSpaceModel[{{-(x1/10) - Cos[x2^2], Cos[x1]}, {{0}, {1}}, {x1}, {{0}}}, {x1, x2}, Automatic, {Automatic}, Automatic, SamplingPeriod -> None] ]
Out[4]=

Control initial and parameter values in a NonlinearStateSpaceModel:

In[5]:=
ResourceFunction["SystemModelManipulate"][
 NonlinearStateSpaceModel[{{Cos[x] + 4 Sin[(1 + 10 a) x/2]}, {x + Sin[x]}}, {x}, {}, {Automatic}, Automatic, SamplingPeriod -> None]]
Out[5]=

Control parameter and initial values in a StateSpaceModel with a given input:

In[6]:=
ResourceFunction["SystemModelManipulate"][
 StateSpaceModel[{{{0, 1}, {1/4 (-2 - 4 a), -(5/2) - a}}, {{0}, {1}}, {{1, -1}}, {{0}}},
   SamplingPeriod ->None, SystemsModelLabels -> None], <|
  "Inputs" -> {1 -> UnitStep}|>]
Out[6]=

Control a parameter value in a TransferFunctionModel with a given input:

In[7]:=
ResourceFunction["SystemModelManipulate"][
 TransferFunctionModel[
  Unevaluated[{{(s - 1)/(s^2 + (5/2 + a) s + 1/2 + a)}}], s, SamplingPeriod ->None, SystemsModelLabels -> None], <|
  "Inputs" -> {1 -> Tanh}|>]
Out[7]=

Control a parameter value in a DiscreteInputOutputModel with a given input:

In[8]:=
diom = DiscreteInputOutputModel[{{u[0], u[0]}, {u[0] - 100 a u[1], u[0] + u[1]}, {u[0] - u[1] - u[2], u[0] + u[1] + u[2]}}, u]
Out[8]=
In[9]:=
ResourceFunction[
 "SystemModelManipulate"][diom, <|"Inputs" -> {1 -> Range[-50, 50]}|>]
Out[9]=

Content (6) 

Reproduce control annotations for a SystemModel:

In[10]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/ee24562f-d7e9-4952-8506-04e44cae8d82"]
Out[10]=

For a SystemModel all default plots are shown by default:

In[11]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/528c7503-0df2-41d8-b5f4-e0aebea9634f"]
Out[11]=

Manipulate all plots individually with a "Plots" control:

In[12]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/16fb2da8-41e2-48cb-bddc-d9e64b31ff06"]
Out[12]=

Select which plots to make available:

In[13]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/3bc8c753-0ce6-4c08-84a3-cbb2744ecc51"]
Out[13]=

Use variables or list of variables to specify plots:

In[14]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/d59945cd-9edd-4562-bb50-4f81bdb6b185"]
Out[14]=

Specify a custom simulation interval:

In[15]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/ce64f30e-862c-4ac9-9196-d7db8e662c2b"]
Out[15]=

Controls (5) 

Pick minimum and maximum values for the control of a parameter value:

In[16]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/f4a8ed15-176a-4dfd-8a94-1f9f225e541c"]
Out[16]=

Pick minimum, maximum and jump values for the control of a parameter value:

In[17]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/01ac37eb-77b3-4c9f-ac02-d4b2caa72af8"]
Out[17]=

Pick an initial value for the control of a parameter value:

In[18]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/77b61f29-4c3c-438d-911f-bd268d59520b"]
Out[18]=

Pick a list of discrete values for the control of a parameter:

In[19]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/98981c9a-4e58-4756-98ff-60a1d49ab238"]
Out[19]=

Pick a function for the control of a parameter:

In[20]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/5fb88e0d-7987-4ade-a36b-4a9bdf030131"]
Out[20]=

Presentation (4) 

Pick a label for the control of an initial value:

In[21]:=
ResourceFunction["SystemModelManipulate"][
 AffineStateSpaceModel[{{-(x1/10) - Cos[x2^2], Cos[x1]}, {{0}, {1}}, {x1}, {{0}}}, {x1, x2}, Automatic, {Automatic}, Automatic, SamplingPeriod -> None] , {{x1, 5, Style["State 1", Bold]}, 0, 10}]
Out[21]=

Pick a list of discrete values and their labels for the control of a parameter:

In[22]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/19dcca5a-f19e-40dd-8114-216f90163a46"]
Out[22]=

Controls for booleans and enumerations use PopupMenu as ControlType if they are not specified:

In[23]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/2327ab32-35a7-4dc2-9be4-a80b6c0196e2"]
Out[23]=

If provided in the model, the base unit is displayed next to the name of the variable or parameter and the description is shown with Tooltip:

In[24]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/41d14a72-7bea-443f-b8aa-9c16ae7ae170"]
Out[24]=

Simulation Specification (3) 

Set a fixed initial value:

In[25]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/48c29538-5fa7-47a2-9e57-1801ba6868e7"]
Out[25]=

Set a fixed parameter value:

In[26]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/015ed2a2-dc8a-4147-882e-ab6e8554a88d"]
Out[26]=

Set an input:

In[27]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/ae3941dd-b646-446c-8bdc-ec93b3ab60d8"]
Out[27]=

Options (2) 

Appearance (2) 

Real and integer values are displayed by default:

In[28]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/9a037d05-2fe6-42fd-bbff-e18c255521a6"]
Out[28]=

Remove displayed values:

In[29]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/cab30afa-912f-43ad-9e29-4c27a2383bd3"]
Out[29]=

Applications (4) 

Study the trajectory of a classical charged particle under the effect of the Lorentz force:

In[30]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/5911fc5e-b962-4701-a86d-8f1b5f3d03f3"]
Out[30]=

Visualize trajectories in the configuration space of a Duffing oscillator:

In[31]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/3d9f07c0-eadc-4ac4-be68-b700d782a815"]
Out[31]=

Visualize trajectories and mass loss of a rocket with exhaust velocity of constant magnitude:

In[32]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/dc0ec1a6-becd-4e73-abf5-ccc11860882b"]
Out[32]=

Study the model of a thumb-wheel potentiometer connected in a rheostat configuration:

In[33]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e38d868d-97c8-4eae-b70e-3bacbff33c5b"]
Out[33]=

Properties and Relations (1) 

Use Setting on the output to access the displayed plots:

In[34]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/13eef4b1-8b0d-48ed-a13a-3ac80e27fa77"]
Out[34]=

Neat Examples (1) 

Observe the trajectories of 5 balls released inside a room, varying the size of the room using parameters:

In[35]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/f9bf2906-9956-4697-be3e-09feadd66024"]
Out[35]=

Publisher

Sergio Vargas

Version History

  • 1.1.0 – 13 December 2022
  • 1.0.0 – 05 April 2022

Related Resources

License Information