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

Changing equations permanently

Changing equations permanently

I have a problem that should be easy but I could not solve.
I want to write a block  that receives x as input and creates y.

It should be:
     y =0                  up to when x > xMax for the first time
and:
     y=1                  after that.
It should be  y=1 even if later x is back below xMax.

Someone can help?

Re: Changing equations permanently

Code:

model M

  Real x,y(start = 0.0);
  parameter Real xMax = 0.5;
equation
  der(x) = sin(time);
  when x > xMax then
    y = 1.0;
  end when;
end M;

Re: Changing equations permanently

Thanks.
It  is easy and effective.
The when clause indeed opens to me a new world of  options and possibilities.
MC

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