- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » division by zero problem
division by zero problem
division by zero problem
Hello,
i just wrote a simple program as follows:
Code:
model tmp
parameter Real x(fixed = false);
parameter Real y = 1 / x;
initial equation
x = 2;
equation
end tmp;
when i run this program i get the following error:
division by zero at time 0, (a=1) / (b=0), where divisor b expression is: x
i slightly modified the above code as follows:
Code:
model tmp
parameter Real x(fixed = false);
parameter Real y(fixed=false);
initial equation
x = 2;
y = 1 / x;
equation
end tmp;
and the error did not appear anymore.
could you please explain me, why this happens?
Thanks,
Arvin
Re: division by zero problem
Hi,
It seems that in the first code, x is unevaluated when the code reaches y=1/x. And perhaps 0 is used as a default value for x.
In the second code, the value 2 is already assigned to x when the code reaches y=1/x.
Gregory
- ggtlse
- 14 Posts
Re: division by zero problem
I suppose it since I just begin with this language.
Also 'parameter' seems to be a keyword reserved for constants.
What do you want to do with this code ?
- ggtlse
- 14 Posts
Re: division by zero problem
suppr
- ggtlse
- 14 Posts
Re: division by zero problem
You could try and use the first version with the change that you set a start value for x like this:
Real x(start=2);
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » division by zero problem