As stated above: I want to calculate the minimum (and / or maximum) of a continuous variable over time. Here is a minimal example to demonstrate:
model MinMaxTest
Real u;
Real u_min(start = 10);
Real u_max(start = -10);
equation
u = sin(time / 180 * Modelica.Constants.pi);
u_min = min(u, u_min);
u_max = max(u, u_max);
annotation(experiment(StartTime = 0, StopTime = 360, Tolerance = 1e-06, Interval = 1));
end MinMaxTest;
u- an arbitrary continuous variable (for demonstration purposes - a simple sinus wave).
u_min/ u_maxis minimum / maximum over time.
Obviously, the expected result u_min=-1and u_max=1. Unfortunately, the simulation crashes with the "Singular Matrix!" error. Can someone guide me how to avoid this?
EDIT 1
I am using OpenModelica 1.15 (was 1.9.2)
EDIT 2
Since I'm completely new to Modelica, I try my best to understand the differences between the following 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;u_min = if noEvent(u < u_min) then u else u_min;u_min = if u < u_min then u else pre(u_min);u_min = if u < u_min then u else u_min;when u < u_min then
u_min = u;
end when;u_min + T*der(u_min) = if u <= u_min then u else u_min;
1 2 .
3 , " " " ", ?
4 , u_min u?! ?
5 3 4.
6 Sorry - Support for Discrete Equation Systems is not yet implemented
7 , , , T .
Modelica, 1-5 , . noEvent . , . 4, ? pre , , , , , 7 ? when , , 6. , , ).
EDIT3
u_min = smooth(0, if u < u_min then u else pre(u_min));
, .