[R-sig-dyn-mod] deSolve::ode workaround for solutions with NaN

Thomas Petzoldt Thomas.Petzoldt at TU-Dresden.de
Mon Jun 28 22:43:16 CEST 2010

Hi Mike,

an NaN can occur if you apply log(Q) to a negative Q. I guess there are 
several ways to prevent this. Can you please give us a reproducible 
example specifying input1, input2, parameters and time steps. Which 
solver did you use?

Thomas Petzoldt

On 6/28/2010 8:36 PM, Maik Renner wrote:
> Dear List,
> I have a question regarding unstable solutions using deSolve. Due to
> my model equation I get NaN, when my state drops below zero.
> Now, I wish to set the state to some default value, when this happens,
> such that the simulation is continuing without NaNs.
> However I could not figure out how to do that technically.
> An if clause in the Model equation did not help. And I also tried the
> event / root example in the vignette, but it did not run, having some
> problems with my forcing inputs.
> I have a model with one simple differential equation and one state and
> a forcing vector. Here is the model implementation:
> KirchSimeq19<- function(t, state, parameters, input1, input2) {
>   with(as.list(c(state, parameters)),{
>    P<- input1(t)
>    E<- input2(t)
>    dQ<- exp(c1 + c2 * log(Q) + c3 * (log(Q))^2) * ( (P - k_E * E) / Q  - 1)
>   list(c(dQ))
>   }) # end with(as.list...
> }
> Any help  is appreciated,
> Maik

Thomas Petzoldt
Technische Universitaet Dresden
Institut fuer Hydrobiologie        thomas.petzoldt at tu-dresden.de
01062 Dresden                      http://tu-dresden.de/hydrobiologie/

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