Exercise01 Classes Simple Textual
Exercise01 Classes Simple Textual
the VanDerPol model in DrModelica (link from Section 2.1), run it, change it slightly, and re-run it.
1.2HelloWorld
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;
Push shift-tab for command completion, fill in the name HelloWorld, and simulate it!
simul
Push shift-tab for command completion, fill in a variable name (x), and plot it!
plo
Take a look at the intepolated value of the variable x at time=0.5 using the val(variableName,time) function:
val(x,0.5)
model ...
1.4Creating a Class
Create a class, Multiply, that calculates the product of two parameter variables, which are equal to Real numbers with given values.
1.5Creating Instances
class Dog constant Real legs = 4; parameter String name = "Dummy"; end Dog;
Create an instance of the class Dog by declaring a variable. Create another dog instance and give this dog the name "Tim".