使用steady.1D(rootSolve R)求解稳态PDE

时间:2014-03-22 23:22:13

标签: r

我试图获得两种竞争物种(具有空间扩散)的空间显性Lotka-Volterra竞争模型的稳定状态。这是模型(没有扩散术语):

http://en.wikipedia.org/wiki/Competitive_Lotka%E2%80%93Volterra_equations

我让r1 = r2 = rG& alpha12 = alpha 21 = a。假设物种1的承载能力在空间x上线性变化,即K1 = x(而K2 = 0.5)。我们假设Neumann BC。空间域x为0到1.

以下是此模型在R中编码的示例:

LVcomp1D <- function (time, state, parms, N, Da, x, dx) { 
with (as.list(parms), { 
S1 <- state[1:N] 
S2 <- state[(N+1):(2*N)] 

## Dispersive fluxes; zero-gradient boundaries 
FluxS1 <- -Da * diff(c(S1[1], S1, S1[N]))/dx 
FluxS2 <- -Da * diff(c(S2[1], S2, S2[N]))/dx 

## LV Competition 
InteractS1 <- rG * S1 * (1- (S1/x)- ((a*S2)/x)) 
InteractS2 <- rG * S2 * (1- (S2/(K2))- ((a*S1)/(K2))) 

## Rate of change = -Flux gradient + Interaction 
dS1 <- -diff(FluxS1)/dx + InteractS1 
dS2 <- -diff(FluxS2)/dx + InteractS2 

return (list(c(dS1, dS2))) 
}) 
} 

pars <- c(rG = 1.0, a = 0.8, K2 = 0.5) 
dx <- 0.001 
x <- seq(0, 1, by = dx) 
N <- length(x) 
Da <- 0.001 
state <- c(rep(0.5, N), rep(0.5, N)) 
print(system.time( 
out <- steady.1D (y = state, func = LVcomp1D, parms = pars, 
nspec = 2, N = N, x = x, dx = dx, Da = Da, pos = TRUE) 
)) 

mf <- par(mfrow = c(2, 2)) 
plot(out, grid = x, xlab = "x", mfrow = NULL, 
ylab = "N(x)", main = c("Species 1", "Species 2"), type = "l") 
par(mfrow = mf) 

问题是我无法获得模型的稳态解决方案。我不断通过x轴获得水平线。能不能帮助我,因为我不知道这段代码有什么问题。

谢谢

0 个答案:

没有答案