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

divide by zero

divide by zero

Hi,

Trying to simulate a model which worked perfectly using Dymola, I got the error:
Divide by zero
:

equation
  der(H3) = omega;
  der(H2) = Vx * Modelica.Math.sin(theta)+ X * Modelica.Math.cos(theta) * omega;
  der(H1) = Vx* Modelica.Math.cos(theta)+ X * Modelica.Math.sin(theta) * omega;
  Vx = Y * omega;
  Vy = - omega * X ;

  der(theta) = (-Vx) / X;
  der(X) = Modelica.Math.cos(theta) * Vx- Modelica.Math.sin(theta) * Vy;
  der(Y) = Modelica.Math.sin(theta) * Vx+ Modelica.Math.cos(theta) * Vy;
  (-Modelica.Math.sin(theta) * der(X)) + X * der(theta) = 0;

Re: divide by zero

Well, you should try to find out, which variable becomes zeros. The only division in the above model is   der(theta) = (-Vx) / X, but that doesn't necessarily mean, that it's that one, since the equations are getting rearranged in the order the computer needs them. You can try to do something like this:
der(thetha) = -(Vx) / (max(1e-5, abs(X))* sign(X))
At least for my calculations this often works well. I can't tell you why Dymola is handling this well why OM doesn't, though.

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