[R-sig-dyn-mod] Time steps of integration

Daniel Reed reeddc at umich.edu
Tue Nov 5 13:20:27 CET 2013


Hi Lena:

That’s a good question. I’m sure one of the authors of deSolve can give you a better solution, but here are my thoughts based on my limited understanding of how the ODE integrators work. One approach is to define a global array that stores step times, say, gl.t. So, before the model solution you could define your start point

#Start time is zero
gl.t <- 0

Then, in your model function, have some code like this:

if( t > gl.t[length(gl.t)] ) gl.t <<- c( gl.t, t)
else gl.t[length(gl.t)] <<- t

This (untested) piece of code checks to see if the current time used by the ODE solver, t, is later than the previously recorded time. If so, it tags it on to the end of the gl.t array. If not, in the case where ODE solver is trying a smaller time step for the same point in time, the previously recorded value is overwritten. After solving the model, you can determine the time steps using,

timesteps <- diff(gl.t)

As I say, this is an untested idea, but hopefully it helps.

Cheers,
Daniel

PS There is a function called timestep() that I thought was for this very purpose, but it seems to behave differently to how I anticipated. I think this was briefly discussed on this mailing list a while ago.

_______________________________
Daniel C. Reed, PhD.
Postdoctoral Fellow,
Dept. of Earth & Environmental Sciences,
University of Michigan,
Ann Arbor, MI, USA.
email: reeddc at umich.edu
web: www.danielreed.org

On Nov 5, 2013, at 4:57 AM, Lena Appel <jumpingfrog at hotmail.com> wrote:

> Dear all,
> 
> I face some trouble trying to figure out the real step size of the integration, when using the ode solver (radau, ode23... etc). I get a summary with verbose telling me how many time steps it used in total, but I would rather need a vector with all time steps.
> Is there also a possibility to get the time needed for the integration, although I think I can handle this with the help of proc.time or system.time.
> 
> Thanks a lot in advance,
> Lena
> 		 	   		  
> 	[[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



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