[R-sig-dyn-mod] Skinny square waves (John Harrold)

John Harrold john.m.harrold at gmail.com
Thu Mar 9 02:56:00 CET 2017


Howdy Steve,

I've run into this problem in the past in Matlab. I tested it in R at the
time and I didn't seem to have the same problem. But it seems to be
somewhat situational :).

I had a similar solution in Matlab to what you did. The R-equivalent of
adding events at each of the switching times. So as a test I added events
at each of the switching times. Basically I told ode to add 0 to the first
state at each of those times, and that seemed to do it. These events should
force the ode solver to stop and restart at each time point. Now I just
need to automate this in my simulation routines.

I think it would be good if we could just provide the ode function a list
of times and have it do this automatically. This way it would make it
easier for me :). And it would also allow this to be optimized better than
my poor coding skills will probably allow. Is this the appropriate list to
make these suggestions?

John

On Wed, Mar 8, 2017 at 8:33 PM, Stephen Paul Ellner <spe2 at cornell.edu>
wrote:

> John,
>
> the efficient deSolve solvers can't deal with such rapid on-off changes
> (even if you make the changes continuous). And even with start and stop
> times in the output times, the solvers may well leap over the 30 minute
> periods when the forcing is 'on' and give you interpolated output values
> for output times during the 'on' periods.
>
> The way I've always dealt with such situations is to solve the 'on' and
> 'off' periods separately.
>
> for(j in 1:whatever) {
>         solve from stop[j] to start[j+1] with forcing=0
>         solve from start[j+1] to stop[j+1] with forcing = value
> }
> storing the results along the way in one big data frame or matrix.
>
> Steve
>
> Stephen P. Ellner
> Department of Ecology & Evolutionary Biology, E339 Corson Hall
> Cornell University, Ithaca NY 14853-2701
>
> _______________________________________________
> 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