 Maximum value of a continuous variable, computing the maximum value of a variable during a simulation Options Roland May 6 2009, 10:11 AM Post #1 Advanced Member   Group: Members Posts: 30 Joined: 2-January 08 Member No.: 5,272 How about this:CODEblock HoldMax extends Modelica.Blocks.Interfaces.SISO;  parameter Modelica.SIunits.Time delaytime(min=1E-4)=0.001;equation   if der(u) > 0 then    der(y) = if u > y then der(u) else 0;  else    der(y) = 0;  end if;end HoldMax;Uses the derivative again. Should only be a problem with discontinuous input signals.Roland   RungeZipperer Apr 14 2009, 09:04 AM Post #2 Advanced Member   Group: Members Posts: 59 Joined: 14-March 06 Member No.: 4 It´s not so easy using continuous signals. Using discrete signals is very easy but leads to slower simulation speed. Another approach (not tested) could be:CODEblock HoldMax extends Modelica.Blocks.Interfaces.SISO;  parameter Modelica.SIunits.Time delaytime(min=1E-4)=0.001;protected   discrete Real max(start=0);algorithm   when noEvent(abs(delay(u, delaytime)))>max then    max:=noEvent(abs(u));  end when;  y:=max;end HoldMax;   Lars Apr 14 2009, 06:46 AM Post #3 Member  Group: Members Posts: 18 Joined: 30-October 06 Member No.: 81 Have you tried something along the lines of y=max((u), pre(y))to avoid the nonlinear equation?   Jonathan Apr 2 2009, 11:28 AM Post #4 Newbie Group: Members Posts: 7 Joined: 17-July 08 Member No.: 13,883 Hello,I try to obtain the maximum value of a continuous variable. For this I have used two different approaches:For the two approaches u = input and y = output (i.e. the max value of u)1 - y=max((u), y)This solution involvess non-linear solving and makes th e simulation heavier.2- Detection of a max value by using a derivative of the input signal u. Comparing this value with the precendent detecting local maximum and keeping the bigger (bloc triggeredMax in the standard Modelica Library).This solution requires a derivation and is not efficient in case of a monotonic varaition of the input signal.Do you know another more efficient solution ?Thanks in advance.   1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: Lo-Fi Version Time is now: 18th January 2020 - 02:13 PM