As stated above: I wish to compute the minimum (and/or maximum) of a continuous variable over time. Here is a minimal example to demonstrate:
model MinMaxTes
The main issue here is that you get an equation which is singular, since you try to solve the equation u_min = min(u,u_min). Where u_min depends on u and u_min and every value of u_min that is smaller than u would fit in that equation, also a tool might try to use a non-linear solver for that.
An other solution for that could be perhaps the delay operator:
u_min = min(u, delay(u_min,0));
u_max = max(u, delay(u_max,0));
Some notes on the different approaches:
u_min = if noEvent(u < u_min) then u else pre(u_min);if noEvent(u < u_min) then
u_min = u;
else
u_min = pre(u_min);
end if;These both are semantically identical, so the result is should be the same. Also the usage of the pre operator solves the issue, since here u_min depends on u and pre(u_min), so there is no need for a non-linear solver.
u_min = if noEvent(u < u_min) then u else u_min;Like above where min() is used here the solution of u_min depends on u and u_min, what leads to a non-linear solution.
The semantic of the noEvent() operator results into literally usage the if-expression, in this case here an event u < u_min is triggered and the expression u_min = u is used all the time.
u_min = if u < u_min then u else u_min;Yes, it combines the problems of 3 and 4.
when u < u_min the
u_min = u;
end when;Here again the solution of u_min depends on u_min and u.
u_min + T*der(u_min) = if u <= u_min then u else u_min;Here u_min is a state and so the calculation of u_min is done by the integrator and this equation is now solved for der(u_min), which then effects u_min.