- Index
- » Programming
- » Modelica Language
- » Change equation in a if-elseif-else...
Page Start Prev 1 Next End
Change equation in a if-elseif-else statement?
Change equation in a if-elseif-else statement?
Nov-17-17 20:40:17
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?
Page Start Prev 1 Next End
- Index
- » Programming
- » Modelica Language
- » Change equation in a if-elseif-else...
There are 0 guests and 0 other users also viewing this topic