[R-sig-dyn-mod] timestep()

Daniel Reed reeddc at umich.edu
Wed Aug 7 19:26:12 CEST 2013


Hi Thomas:

Thanks for the reply. Using your example, if I specify times=c(0,2) then I can see the ODE solver stepping through time, but it always gives a time step of zero. For example,

time= 0 timesteps= 0 0 
time= 0 timesteps= 0 0 
time= 9.424322e-08 timesteps= 0 0 
time= 0.01842312 timesteps= 0 0 
time= 0.009211559 timesteps= 0 0 
time= 0.009211559 timesteps= 0 0 
time= 0.009211559 timesteps= 0 0 
time= 0.009211559 timesteps= 0 0 
time= 0.01842312 timesteps= 0 0 
time= 0.109853 timesteps= 0 0 
time= 0.109853 timesteps= 0 0 
time= 0.04351654 timesteps= 0 0 
time= 0.04351654 timesteps= 0 0 
time= 0.06860996 timesteps= 0 0 
time= 0.09370338 timesteps= 0 0 
time= 0.1187968 timesteps= 0 0 
time= 0.1698147 timesteps= 0 0 
time= 0.2625042 timesteps= 0 0 
time= 0.3551938 timesteps= 0 0 
time= 0.4478833 timesteps= 0 0 
time= 0.5405728 timesteps= 0 0 
time= 0.5405728 timesteps= 0 0 
time= 0.7372618 timesteps= 0 0 
time= 0.7372618 timesteps= 0 0 
time= 0.9339508 timesteps= 0 0 
time= 1.13064 timesteps= 0 0 
time= 1.327329 timesteps= 0 0 
time= 1.524018 timesteps= 0 0 
time= 1.720707 timesteps= 0 0 
time= 2.066925 timesteps= 0 0 
time= 2.066925 timesteps= 0 0 

Setting the verbose option to TRUE in ode() tells me that 18 steps were taken and that the last successful time step size was 0.3462188, yet the timestep() function doesn't report this. 

Cheers,
Daniel

_______________________________
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 Aug 7, 2013, at 12:41 PM, Thomas Petzoldt <Thomas.Petzoldt at TU-Dresden.de> wrote:

> Hi Daniel,
> 
> I cannot see a problem with vode:
> 
> model <- function(t, y, parms) {
>  cat("time=", t, "timesteps=", timestep(TRUE), timestep(FALSE), "\n")
>  with (as.list(c(y, parms)), {
>    dP <- a * P      -  b * P * K
>    dK <- b * P * K  -  c * K
>    list(c(dP, dK))
>  })
> }
> 
> parms <- c(a = 0.1, b = 0.1, c = 0.1)
> 
> y <- c(P = 1, K = 2)
> 
> out <- ode(y = y, func = model, times = seq(0, 2, .1),
>  parms = parms, method="vode")
> 
> 
> #####
> 
> ... and it works also when using the first example of ?ode.1D and "vode" as the solver with:
> 
> cat("time=", time, "timesteps=", timestep(TRUE), timestep(FALSE), "\n")
> 
> 
> Can you please provide a *minimal* reproducible example?
> 
> Thomas
> 
> 
> On 8/7/2013 5:46 PM, Daniel Reed wrote:
>> Hi all:
>> 
>> I have a question about the function timestep() in the package
>> deSolve. Whenever I call timestep() from the model function that is
>> being solved by ode.1D() using the vode method, the return value I
>> get is always zero – both when using prev=TRUE or prev=FALSE. [I'm
>> checking by using print(timestep()) in my model function.] Any ideas
>> why this is the case? Does this function not work with vode or
>> ode.1D, or am I using it incorrectly?
>> 
>> Thanks in advance, Daniel
>> 
>> _______________________________ 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
>> 
>> _______________________________________________ R-sig-dynamic-models
>> mailing list R-sig-dynamic-models at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
>> 
> 
> 
> -- 
> Dr. Thomas Petzoldt
> Technische Universitaet Dresden
> Faculty of Environmental Sciences
> Institute of Hydrobiology
> 01062 Dresden, Germany
> 
> E-Mail: thomas.petzoldt at tu-dresden.de
> http://tu-dresden.de/Members/thomas.petzoldt
> 
> _______________________________________________
> 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