[R-sig-dyn-mod] ode with variable parameters

Thomas Petzoldt thomas.petzoldt at tu-dresden.de
Thu Feb 9 14:31:08 CET 2017


Hi,

yes, compiled code supports this, and it can also be done in plain R 
with approxfun:

library(deSolve)

model <- function(t, y, p, signal) {
   sig <- signal(t)
   dX <- sig * y["X"] + p
   list(dX)
}

time <- 1:100
parms <- c(p = 0.2)

y    <- 0.1 * c(rep(0, 25), rep(1, 25),  rnorm(25), rep(-1, 25))
signal <- approxfun(time, y, rule=2)

y0 <- c(X=1)
out <- ode(y0, times=time, func=model, parms=parms, signal=signal)
plot(out)


One has to take care, however, that interpolation can be time consuming. 
There are several methods to make it faster, but this would be another 
story ...


ThomasP.

Am 09.02.2017 um 12:17 schrieb Johannes Ranke:
> Hi Thomas,
>
> if you use method = "lsoda" (the default for ode.1D), if you pass "dllname"
> (pointing to a precompiled version of your model) you can specify "forcings".
>
> See chapter 6 of the vignette "compiledCode" of the deSolve package.
>
> Kind regards,
>
> Johannes
>
> Am Montag, 6. Februar 2017, 11:09:42 schrieb Thomas.Hoffmann at bafg.de:
>> Dear all,
>>
>> I would like to solve a simple diffusion-advection equation: dC/dt = v * C +
>> gamma dC/dx
>>
>> In which v and gamma changes through time. Basically I have a dataframe,
>> which gives v and gamma at the time-steps that I use to solve the above
>> equation with ode.1d.
>>
>> How do I solve this problem dynamically with variable parameters.
>>
>>
>> Thanks for your help
>> Kind regards
>> Thomas


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

-- limnology and ecological modelling --



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