Exercises To Introductory Modelica Tutorial: 1 Short Introduction To Graphical Modeling
Exercises To Introductory Modelica Tutorial: 1 Short Introduction To Graphical Modeling
Modelica Tutorial
1 Short Introduction to Graphical Modeling
Install OpenModelica and start OpenModelica OMNotebook. Also and start the OpenModelica Connectio
Graphical Connection Editor called OMedit..
Do the RL-Circuit exercise in the course slides.
1
class DAEexample
Real x(start=0.9, fixed=true);
Real y(start=0);
equation
der(y)+(1+0.5*sin(y))*der(x) = sin(time);
x - y = exp(-0.9*x)*cos(y);
end DAEexample;
{DAEexample}
Simulate the example
simulate(DAEexample, stopTime = 1)
[done]
Plot the results. Notice that while the start value of x is fixed, the start value of y is not fixed. Non-fixed st
values are treated by the simulator as "guess" values. During initializiation this guess value will be tried a
starting value, but the simulator can change them in order to produce a set of consistent initial condition.If
linear system of equations needs to be solved during initialization, such guess values will be used by the
simulator as a starting point (guess value) for root-finding algorithms such as Newton's method..
plot({x,y})
true
model ...
2 Functions
.
5
a) Write a function, sum2, which calculates the sum of Real numbers, for a vector of arbitrary size.
function sum2
...
end sum2;
{sum2}
b) Write a function, average, which calculates the average of Real numbers, in a vector of arbitrary size. T
function average should make use of a function call to sum2
function average
...
2
end average;
{average}
Test the functions
average({1,2,3})
2.0
model ...
[1:7]: error: unexpected token: .
You can simulate and plot the model directly from the graphical editor. Simulate for 15s and plot the varia
the outgoing rotational speed on the inertia axis and the voltage on the voltage source (denoted u in the fig
the same plot.
Option: You can also save the model, load it and simulate it using OMShell or OMNotebook. You can also
3
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 varia
plot, you can flatten the model by calling instantiateModel, which exposes all variable names.
model ...
[1:7]: error: unexpected token: .
model ...
[1:7]: error: unexpected token: .