[R-sig-dyn-mod] ode with variable dependent on results from previous time step
Guadalupe Peralta
gdlp.peralta at gmail.com
Mon Feb 27 05:02:07 CET 2017
*Dear all,
*
*I'm using the ode function and I wonder how to incorporate a variable
into the model that results from a previous time step.*
*Lets say I have two groups of organisms (P and A) with multiple
species within each group (nP=3, nA=2). Species from group A interact
with species from group P, with an interaction coefficient of 'c'. My
function (funcPA) describing the changes in time is as follows:*
funcPA <- function (t, y, params, nsp) {
with(as.list(c(y,params)), {
nP <- nsp[1]
nA <- nsp[2]
ntot <- nP + nA
P <- y[1:nP]
A <- y[(nP + 1):ntot]
dP <- array(0, nP)
dA <- array(0, nA)
c <- params$c
for (i in 1:nP) {
for (j in 1:nA){
dP[i] <- P[i] + sum(c*A[j]*P[i])
dP
dA[j] <- A[j] + sum(c*P[i]*A[j])
dA }}
res <-list(c(dP, dA))
})
}
nsp <- c(nP=3, nA=2)
c <- list()
c[[1]] <- matrix(c(0.1,0.11,0.12,0,0,0.1),nrow=3, ncol=2)
y <- c(P1=2, P2=1, P3=2, A1=1, A2=2)
ode(y=y, times=seq(0,1,by=0.1), func=funcPA, nsp=nsp, parms=c)
*Now, I want to include a variable Ak on the dP[i] equation of the
funcPA function so that it looks like this:*
dP[i] <- P[i] + sum((c*A[j]*P[i]) / (Ak[i]))
*where Ak[i] is the number of individuals from group A (considering
all A species) that interact with each particular P species (P[i]) on
each time step. For the first time step Ak can be calculated from the
initial abundances of species As (i.e. A1=1, A2=2) and a binary
version of the interaction coefficients 'c' (to determine which A
species interact with each P species). However, as the abundances of A
will change from one time step to the next, I wonder how should I
include it the equation? or should I include Ak somehow in the ode
function?*
*Thanks for your help.
Kind regards
Guadalupe
*
[[alternative HTML version deleted]]
More information about the R-sig-dynamic-models
mailing list