Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Please let me know why this model wouldn't run

Please let me know why this model wouldn't run

When I try to run the simulation for individual values of 'a' (i.e. a[1] = 16 and 1[2] = 14) seperately the program works fine. But when I try to loop the same with using the program below it shows an error that says "division by zero (1-x)/x". Please tell me what I'm doing wrong. Thanks.

model Test
parameter Real a[2] = {16,14};
parameter Real b = 15, c =2 ;
Real x,y;
algorithm
for i in 1:2 loop
x := if a[i] < b and a[i] > c then (a[i] - c)/(b-c) else 0;
y := if x > 0 then ((1-x)/x)^0.5 else 0;
end for;
end Test;

Re: Please let me know why this model wouldn't run

I can confirm this model runs fine in Dymola 2016, even in pedantic mode. I would guess it is a problem with events. Try using very small value (e.g. 1e-6 ) instead of hard 0.

F/

Re: Please let me know why this model wouldn't run

Thanks, jez
When I run the model on Open modelica and it still shows me the error for the code given above. Anyway, I found a fix for it.


model Test
parameter Real a[2] = {16,14};
parameter Real b = 15, c =2 ;
Real x,y;
algorithm
for i in 1:2 loop
x := if a[i] < b and a[i] > c then (a[i] - c)/(b-c) else 0;
y := noEvent(if x > 0 then ((1-x)/x)^0.5 else 0);
end for;
end Test;

This works just fine now.

There are 0 guests and 0 other users also viewing this topic
You are here: