Help - Search - Members - Calendar
Full Version: How to initialize an array of objects?
Modelica Forum > Modelica > Modelica
daniel@ka
To make the long story short here is my code

package math

model second_order
parameter Real y0 = 1;
parameter Real ydot0 = 1;
Real x;
Real y(start = y0);
Real ydot(start = ydot0);
equation
ydot = der(y);
der(ydot) + der(y) + y = x;
x = if time < 5 then time else 10-time;
end second_order;

model test
second_order so[10];
//second_order so[10](each y0 = 1);
second_order so[10](start ((start y0 = i) for i in 1:10)); // (*)
end test;

end math;

I want to perform kind of a sweep over y0, therefor I need somehow to
pass i value into y0, but I am not sure there is some syntax for this.
Is it possible?

Thx, daniel

ps: Line marked with (*) is not correct, but shows what my intention is.
Roland
Hello Daniel,

QUOTE(daniel@ka @ Apr 12 2009, 08:42 PM) *

second_order so[10](start ((start y0 = i) for i in 1:10)); // (*)


I guess, a solution for you would be:
CODE
second_order so[10](y0(start = {i for i in 1:10}));


I hope this works for you.

Roland
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.