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

Change equation in a if-elseif-else statement?

Change equation in a if-elseif-else statement?

Hi!

Let's say that we have those equations:

Code:


// Compute the flow out.
  C2.Q = (A2*v*6)/ve;
// Set the position
  rod.s = s;
// Compute the derivative of position
  v = der(s);
// ODE equation of the cylinder
  M * der(v) = 10 * A1 * C1.P * me + rod.f + 10 * A2 * C2.P * me;

But let's say that I want my code to look like this:


Code:


// Compute the flow out depending on v
if v > 0 then
  C2.Q = (A2*v*6)/ve;
elseif v < 0 then
  C1.Q = (A1*v*6)/ve;
else
  C1.Q = 0;
  C2.Q = 0;
end if;

// Set the position - With saturation
if s > maxL then
  rod.s = maxL;
  s = 0;
elseif s < 0 then
  rod.s = 0;
  s = 0;
else
  rod.s = s;
end if;

// Compute the derivative of position
  v = der(s);
// ODE equation of the cylinder
  M * der(v) = 10 * A1 * C1.P * me + rod.f + 10 * A2 * C2.P * me;

The problem here is that code would result a very bad simulation. It won't probably work. My equation is how I can implement if-elseif-else statement to "change" equation? For example: If the velocity v is greater that 0, then my equation for liquid flow is going to be this. But if the velocity is less that 0, then my equation for liquid flow is going to be this insted.

Do you know how to do?

Re: Change equation in a if-elseif-else statement?

Nobody knows how to do a IF-statement for equations?

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