System Dynamics is an approach to understanding the behaviour of complex systems over time. It deals with internal feedback loops and time delays that affect the behaviour of the entire system. What makes using system dynamics different from other approaches to studying complex systems is the use of feedback loops and stocks and flows. These elements help describe how even seemingly simple systems display baffling nonlinearity

Here is how a system diagram looks like:

enter image description here

Apperently I should be able to this with System Modeler by loading this modelica library but I am also told here that:

The downside, as I understand it, is that each different use of a System Dynamics symbol requires its own entry in the library. For example, a stock with one inflow and one outflow requires a different Modelica symbol from one with one inflow and 2 outflows. Also (again, as I understand it), every separate equation requires its own symbol to be defined and added to the library before it can be used.

¿Anyone here can confirm or deny this? ¿Is this a limitation inherent in all Modelica enviroments? ¿or it is an implementation limitation on this particular library?

and, going back to the original aim of this question: Is there a less expensive way (than System Modeler) to do this in Mathematica, without System Modeler?

  • $\begingroup$ I am surprised that there is no tags for: "simulation" and "nonlinearity" $\endgroup$
    – Luxspes
    Commented Jul 8, 2012 at 17:00
  • 4
    $\begingroup$ Check wolfram.com/system-modeler/features $\endgroup$ Commented Jul 8, 2012 at 17:02
  • $\begingroup$ I was kind of hoping someone here had first had experience with System Modeler $\endgroup$
    – Luxspes
    Commented Jul 8, 2012 at 17:05
  • $\begingroup$ I found this: modelica.org/libraries/SystemDynamics, apparently since System Modeler uses the Modelica language it should be able to use it. $\endgroup$
    – Luxspes
    Commented Jul 8, 2012 at 17:21
  • 2
    $\begingroup$ I wrote a new answer on that meta thread: meta.mathematica.stackexchange.com/a/542/12 I think that if your question is about doing these simulations in SystemModeler / Modelica, that's off topic. If it's about doing it in Mathematica, it's on topic, but SystemModeler might be a better tool for the task ... $\endgroup$
    – Szabolcs
    Commented Jul 9, 2012 at 10:26

4 Answers 4


The limitation you quote is not a general limitation of Modelica. It is possible to define a Modelica component that has a variable number of inputs/outputs. Typically the number of inputs/outputs is then given by a parameter to that component.

For example, the following component has one input but 2 outputs, varied with the parameter nout:

model SIMO "Single input, multiple output"
  parameter Integer nout=2 "Number of outputs";
  RealInput u "Connector of Real input signal";
  RealOutput y[nout] "Connector of Real output signals";
  {{{your equations}}}
end SIMO;

I have not used the System Dynamics modelica library, so cannot speak to how they have chosen to implement their interfaces.

It would be fully possible to create your custom models in Mathematica by defining equations from the ground up, and then simulating them using for example NDSolve. This would however require a significant amount of manual labor.

If you want to stay in the Wolfram product universe, SystemModeler would be the way to go. It allows you to simulate and interact with models from Mathematica, using a Mathematica package bundled with the product.

An overview of features of the Mathematica package, called WSMLink, can be found at http://wolfram.com/system-modeler/features/analysis-mathematica.html.

Documentation to see how the package actually is used is found at http://reference.wolfram.com/system-modeler/WSMLink/guide/WSMLink.html.


The SystemDynamics library mentioned in the original question is now available for download in a version compatible with Wolfram SystemModeler at the bottom of this blog post: http://blog.wolfram.com/2013/06/11/energy-resource-dynamics-with-the-new-system-dynamics-library-for-systemmodeler/

  • $\begingroup$ And... is there a way to achieve the same without System Modeler? $\endgroup$
    – Luxspes
    Commented Jul 10, 2012 at 23:16
  • $\begingroup$ Certainly possible, but not easy. NDSolve is powerful for solving differential equations, but Mathematica currently does not have an easy way to graphically build dynamic systems. It is of course possible to create "components" (Symbol structures with equations and graphical representations) and build functionality to connect them together, and then using NDSolve to simulate the system, and the Graphics functionality to build up the system diagram. This would be a massive undertaking though. $\endgroup$
    – Malte Lenz
    Commented Jul 11, 2012 at 9:36
  • $\begingroup$ And what about the part " Also (again, as I understand it), every separate equation requires its own symbol to be defined and added to the library before it can be used." Is that true? $\endgroup$
    – Luxspes
    Commented Aug 9, 2012 at 1:50
  • 1
    $\begingroup$ No, that is not true. A class (model or component) in Modelica (and therefore SystemModeler) can contain any number of equations, without defining separate classes for each equation. Of course, if you want to reuse an equation or a collection of equations, for example for the behavior of stock, you can create a class with those equations, and use that class as a component in your bigger model. $\endgroup$
    – Malte Lenz
    Commented Aug 9, 2012 at 7:54

One possible alternative might be Control Systems in Mathematica.

With Control Systems you can carry out analysis, design, and simulation of time control systems.

For an example here an automated house heating system controlled by a thermostat. (Sorry. I really tried to use the drawing tools for a nifty graphic, but...alas...i'm not even able to draw a simple house, so I count on your imagination)

Here I show how to analyze the controller and its performance in a closed loop:

system = TransferFunctionModel[(0.5/((0.2 s + 1) (2 s + 1))), s];

pid = pid = PIDTune[system, Automatic, "PIDData"];

cloop = pid["ReferenceOutput"];

or = OutputResponse[cloop, UnitStep[t], {t, 0, 4}];

p = Plot[%, {t, 0, 4}, PlotRange -> All, Frame -> True, 
  FrameLabel -> {"t", "y"}, LabelStyle -> Directive[15], 
  PlotStyle -> Blue]

enter image description here

Using a PID controller instead reduces the bump a little bit:

pid = pid = PIDTune[system, "PID", "PIDData"];

enter image description here

On Woflram blog in '11 Andrew Moylan wrote two very exciting and amusing posts on stabilising an inverted pendulum (segeway) using Control Systems and with decent animations. (http://blog.wolfram.com/2011/01/19/stabilized-inverted-pendulum/)

Hope that this was informative for you. I know that this is not at all visual modeling, but the principles are the same.

  • $\begingroup$ Any book, website or guide you recommend on how to take a systemdynamics "graphic model" and translate it into something that can be fed in to TransferFunctionModel? $\endgroup$
    – Luxspes
    Commented Aug 17, 2013 at 22:44
  • $\begingroup$ Maybe you could please answer this question: mathematica.stackexchange.com/questions/22798/… using this TransferFunctionModel? $\endgroup$
    – Luxspes
    Commented Aug 17, 2013 at 22:46
  • $\begingroup$ Very interesting answer. Would the Control Systems Framework be able to handle vector equations and could something like WhenEvent be included as in the NDSolve framework? (e.g. what are the downsides of control systems framework as compared to NDSolve) $\endgroup$
    – gwr
    Commented May 2, 2016 at 17:15

Using Modelica for System Dynamics

The way to go for doing System Dynamics (i.e. continuous time, equation based simulations describing the changes of a system's states by flows—essentially reducing a system of higher order ODEs to a system of first-order ODE) within the Wolfram universe is to turn to System Modeler which is built upon Modelica—a simulation language for cyber-physical systems—as Malte has mentioned in his answer.

Downsides of the System Dynamics library

Unfortunately, some of the "downsides" mentioned do indeed apply to the before mentioned System Dynamics library, which is purely build using information or signal flows as I have explained in this tallk(→ minutes 06:28 to 10:00) at the Wolfram Technology Conference 2020. This forfeits a lot of Modelica's powerful features. To give an example, modeling a mass outflow from a stock as an information input, as it is done in that library, means that we cannot leave that connector unconnected in case there is no outflow from the stock. So we will need a special class for a stock having no outflow which is rather cumbersome—a reason why the library is rather unheard of within the system dynamics community.

A new Modelica library for System Dynamics

A lot of the flexibility of Modelica is tied to the use of acausal connectors for physical connections (e.g. the mass flows in System Dyanmics). There is now a new, free library available in the System Modeler Libaray Store: Business Simulation Library (BSL). It makes use of acausal connectors in implementing System Dynamics and offers a lot of the convenience known from dedicated SD tools.

The example of a process of social diffusion given in the OP (e.g. the bass diffusion model of new product adoption) is included as an example in the library, which models the closely related process of epidemic spread in a SIR model:

SIR Model Diagram

As you can see, the process of diffusion is modeled as a compact component Diffusion (e.g. becoming_infected). You can see how it is implemented in the documentation.

  • 3
    $\begingroup$ Great work, Guido! $\endgroup$ Commented Dec 27, 2020 at 16:51

There is an open-source Modelica system called OpenModelica at www.openmodelica.org.

Frankly, I am a little baffled at what you are calling a "downside". Modelica is an object oriented language, so only different classes need to be defined within the library. A single class can be implemented as many objects within your model. For example, a resistor class need only be defined once, but you may have several resistors with different values within your model. I would think that it should be expected that a component governed by a different set of constitutive equations would require a new class. What would you propose as an alternative?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.