[R] A naive lsoda question....

Manojit Roy roym at ufl.edu
Mon Sep 6 17:26:41 CEST 2004


Hello,

I am an R newbie, trying to use lsoda to solve standard 
Lotka-Volterra competition equations. My question is: how do I 
pass a parameter that varies with time, like say, phix <- 0.7 + 
runif(tmax) in the example below.

# defining function
lotvol <- function(t,n,p){
    x <- n[1]; y <- n[2]
    rx <- p["rx"]; ry <- p["ry"]
    Kx <- p["Kx"]; Ky <- p["Ky"]
    phix <- p["phix"]; phiy <- p["phiy"]
    dx.dt <- rx*x*(1 - x/Kx) - phix*x*y
    dy.dt <- ry*y*(1 - y/Ky) - phiy*x*y
    list(c(dx.dt, dy.dt))
}

# running lsoda
nstart <- c(x=0.5, y=0.5)
parms <- c(rx=1, ry=1, Kx=1, Ky=1, phix=1.2, phiy=0.8)
tmax <- 100
times <- seq(0,tmax)
require(odesolve)
out <- as.data.frame(lsoda(nstart, times, lotvol, parms))

Thanks,
Manojit




More information about the R-help mailing list