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

Setzer, Woodrow Setzer.Woodrow at epa.gov
Thu Mar 9 14:45:22 CET 2017


Can you arrange to code this using deSolve's "events"? You would have to code the model so that it is state variables that change abruptly.

Woody

-----Original Message-----
From: R-sig-dynamic-models [mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of Karline Soetaert
Sent: Thursday, March 09, 2017 2:22 AM
To: Special Interest Group for Dynamic Simulation Models in R <r-sig-dynamic-models at r-project.org>
Subject: Re: [R-sig-dyn-mod] Skinny square waves (John Harrold)

Hi John,

Usually in such cases, the problem is that the default solver is too efficient and thus takes too large timesteps. You could either try a less efficient solver that by default takes smaller time steps or restrict the maximal time step (argument hmax).  

Karline

-----Original Message-----
From: R-sig-dynamic-models [mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of John Harrold
Sent: donderdag 9 maart 2017 2:56
To: Special Interest Group for Dynamic Simulation Models in R <r-sig-dynamic-models at r-project.org>
Subject: Re: [R-sig-dyn-mod] Skinny square waves (John Harrold)

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]]

_______________________________________________
R-sig-dynamic-models mailing list
R-sig-dynamic-models at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models

_______________________________________________
R-sig-dynamic-models mailing list
R-sig-dynamic-models at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models



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