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

Maik Renner maikrenner at googlemail.com
Mon Jun 28 20:36:46 CEST 2010


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



-- 
Maik Renner, Dipl. Hydrologist
TU Dresden Germany
Tel.: +49 351 463-31341
http://tu-dresden.de/meteorologie



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