* Frank Bergmann <fbergman@caltech.edu> [2011-05-18 19:24] writes:
> There is a cheaper way of calculating the maximum, that also gets around the
> circular restriction on assignment rule. The basic idea is to have one event
> fire constantly (say every couple of ms) and there you would do your
> assignment. This trigger function is way easier to find (as the rootfinder
> does no longer have to search for the single root at which a != b).
If you don't want your event firing *all* the time, you could instead
introduce the concept of a tolerance. In Antimony format:
model model01()
x := sin(time); //Just to have an x that varies
xmax = x; //An initial assignment
tolerance = 0.00000001; //This can be changed
E0: at(x>xmax+tolerance): xmax=x; //The event
end
Your event will fire a lot as x increases past xmax, but once it goes down
again, the event stops firing. The tradeoff is that xmax will probably be
some fraction of 'tolerance' too low, as we only reassign xmax if x passes
it by a whole tolerance unit.