I am making a population distribution model with ODEs and DDEs in DeSolve with the method lsoda. In this model I want to have an influx of the population at a specific time (a specific day). A very simple example:
dn1dt=influx - mortality
The influx (x) needs to occur at time (t) = y (in days). If it is not day y, I don't want an influx.
At the moment I have written the influx as influx=function(t,y,x){ifelse((t==y), x, 0)), but I am running into the problem of a changing time step due to the method I am using (lsoda). Due to the changing time step, I will not hit the specific time (y) that will trigger the influx.
I am just starting out to work with a changing time step, so I am not sure how to deal with this problem. Please let me know if anything is unclear.
The influx can be implemented as time dependent input (also called "forcing", that lasts a certain time, e.g. a day) or as event, where a state variable is changed immediately. Here an example using a rectangular signal as forcing. Interpolation of time is implemented with
approxfun. The flux function can simply be added as additional argument toodeand to themodel:More can be found on the
?forcingshelp page or at this page.