I’m new on Dymola and I can’t manage to get this code running. I’m trying to create a random generation to simulate the number of people in a room.
Here is the code I have so far. Do you have any idea what could be the problem ?
<code>model Trial
Real p(start=rand()/32767);
Real E(start=1);
equation
when (sample(1,3600)) then//sample(start+interval) ce qui donne "start + i*interval"
p = rand()/32767;
if E == 1 then
if p < 0.2 then
E = 2;
elseif p < 0.6 then
E = 3;
else
E = 4;
end if;
elseif E == 2 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 3;
else
E = 4;
end if;
elseif E == 3 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 2;
else
E = 4;
end if;
elseif E == 4 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 2;
else
E = 3;
end if;
end if;
end when;
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)),
experiment(StopTime=86400, __Dymola_Algorithm="Dassl"));
end Trial;
</code>
<code>model Trial
Real p(start=rand()/32767);
Real E(start=1);
equation
when (sample(1,3600)) then//sample(start+interval) ce qui donne "start + i*interval"
p = rand()/32767;
if E == 1 then
if p < 0.2 then
E = 2;
elseif p < 0.6 then
E = 3;
else
E = 4;
end if;
elseif E == 2 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 3;
else
E = 4;
end if;
elseif E == 3 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 2;
else
E = 4;
end if;
elseif E == 4 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 2;
else
E = 3;
end if;
end if;
end when;
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)),
experiment(StopTime=86400, __Dymola_Algorithm="Dassl"));
end Trial;
</code>
model Trial
Real p(start=rand()/32767);
Real E(start=1);
equation
when (sample(1,3600)) then//sample(start+interval) ce qui donne "start + i*interval"
p = rand()/32767;
if E == 1 then
if p < 0.2 then
E = 2;
elseif p < 0.6 then
E = 3;
else
E = 4;
end if;
elseif E == 2 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 3;
else
E = 4;
end if;
elseif E == 3 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 2;
else
E = 4;
end if;
elseif E == 4 then
if p < 0.2 then
E = 1;
elseif p < 0.6 then
E = 2;
else
E = 3;
end if;
end if;
end when;
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
coordinateSystem(preserveAspectRatio=false)),
experiment(StopTime=86400, __Dymola_Algorithm="Dassl"));
end Trial;
New contributor
Julien Biancucci is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.