- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Please let me know why this model...
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;
- knkc
-
-
- 14 Posts
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.
- knkc
-
-
- 14 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Please let me know why this model...