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

relation problems

relation problems

i want create a ratio between i1 and i2 this ratio should have a range from 0 to 1
so i try

Code:

ratio=smooth(2, if i1>i2 then 

i2/i1 else
i1/i2);

but ratio reaches a value of round about 1.049 so i tried

Code:

helpratio=smooth(2, if i1>i2 then 

i2/i1 else
i1/i2);
if helpratio>1.0 then
ratio=1.0 else
ratio=helpratio
end if;

but again ratio reaches round about 1.049

then i tested if the second if loop is used

Code:

helpratio=smooth(2, if i1>i2 then 

i2/i1 else
i1/i2);
if helpratio>1.0 then
ratio=1.0 else
ratio=1.0
end if;

then ratio was always 1 but now helpratio has the expected characteristics(between 0 and 1) What i have done wrong?

Re: relation problems

Does the following do what you want?

Code:


class A
  Real x = 2-8*time;
  Real y = 1+time^2-time;
  Real ratio = abs(if noEvent(abs(x)>abs(y)) then y/x else x/y);
end A;

Re: relation problems

okay perfect this works

thanks a lot.

P.S. One Question if the noEvent works and smooth not this means that my expression is not continious?

There are 0 guests and 0 other users also viewing this topic