[R-sig-dyn-mod] Limiting State Value to remain below a maximum value

John Harrold john.m.harrold at gmail.com
Mon Jul 27 22:43:17 CEST 2015


Have you thought about simply fixing the derivative of the state you're
interested in? Something like the following that will fix the derivative to
0 if it's greater than what you've specified and the derivative would be
positive. This way if it's negative it can come back down from the max
you're hitting.

ymax = 0.2

mydir = some function of y's and parameters

if((y(2)  >= ymax)& mydir > 0 ){
 mydir = 0.0
}

Then return mydir in your vector of derivatives. It's possible, as a result
of integration error,  for y(2) to jump above ymax


On Mon, Jul 27, 2015 at 12:30 PM, Derek van der Kamp <
derek.vanderkamp at gmail.com> wrote:

> I'm running a model where one of the state variables is required to remain
> below some maximum value (0.6).
>
> I went ahead and wrote an event and root function:
>
> cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
> cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
>
>       subroutine fmcevent(neq, t, y)
>       integer :: neq
>       double precision :: t, y(neq)
>
>       y(2) = 0.58
>
>       return
>       end
>
> cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
> cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
> c     Event function for keeping moisture below M_MAX
>
>       subroutine fmcroot(neq, t, y, ng, gout, out, IP)
>       integer :: neq, ng, IP(*)
>       double precision :: t, y(neq), gout(ng), out(*)
>
>       gout(1) = y(2) - 0.6
>
>       return
>       end
>
> However, this increases the computation time by two orders of magnitude.
> The computation time decreases if I set y(2) to some smaller number, say
> 0.2, in the event function.
>
> My guess is that when I knock the y(2) variable down to just below its
> maximum value, it keeps on hitting that ceiling on subsequent time steps,
> the event function keeps getting called, and this slows everything down.
>
> Is there a more efficient way to keep a state value below some maximum
> value?
>
> Cheers,
>
> Derek
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-dynamic-models mailing list
> R-sig-dynamic-models at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
>



-- 
-------------------------------------
John M. Harrold
john.m.harrold _at_gmail
-------------------------------------

	[[alternative HTML version deleted]]



More information about the R-sig-dynamic-models mailing list