Exercises Modelica Tutorial
Exercises Modelica Tutorial
Version 2012-02-07
Peter Fritzson and Olena Rogovchenko
Install OpenModelica. Start the OpenModelica Connection Editor OMEdit. Do the RLCircuit graphical exercise.
See instructions in slides.
2.1 HelloWorld
Simulate and plot the following example with one differential equation and one initial condition. Do a slight
change in the model, re-simulate and re-plot.
model HelloWorld "A simple equation"
Real x(start=1);
equation
der(x)= -x;
end HelloWorld;
2.3 DAEExample
Locate the DAEExample in DrModelica (Section 2.1: Differential Algebraic Equation System). Simulate and plot.
2.4 A Simple Equation System
Develop a Modelica model that solves the following equation system with initial conditions:
b) Write a function, average, which calculates the average of Real numbers, in a vector of arbitrary size. The
function average should make use of a function call to sum.
You can simulate and plot the model directly from the graphical editor. Simulate for 15s and plot the variables for
the outgoing rotational speed on the inertia axis and the voltage on the voltage source (denoted u in the figure) in
the same plot.
Option: You can also save the model, load it and simulate it using OMShell or OMNotebook. You can also go to
the graphical editor text view and copy/paste the model into a cell in OMNotebook.
Hint: if you use the plot command in OMNotebook and you have difficulty finding the names of the variables to
plot, you can flatten the model by calling instantiateModel, which exposes all variable names.