在 R 包 phaseR 中绘制 ODE 相位 potriat 时出错

Error while plotting ODE phase potriat in R package phaseR

我正在尝试使用 phaseR 包在 R 中绘制二维相图。这是我想要做的一个例子:

有效的例子

library(phaseR)

lotkaVolterra <- function(t, y, parameters) {
x <- y[1]
y <- y[2]
lambda  <- parameters[1]
epsilon <- parameters[2]
eta     <- parameters[3]
delta   <- parameters[4]
dy    <- numeric(2)
dy[1] <- lambda*x - epsilon*x*y
dy[2] <- eta*x*y - delta*y
list(dy)
}

然后当我绘制它时我得到

lotkaVolterra.flowField <- flowField(lotkaVolterra, x.lim = c(0, 5), y.lim = c(0, 10), parameters = c(2, 1, 3, 2), points = 19, add = FALSE)

grid()


lotkaVolterra.nullclines <- nullclines(lotkaVolterra, x.lim = c(-1, 5), y.lim = c(-1, 10), parameters = c(2, 1, 3, 2), points = 500)

y0 <- matrix(c(1, 2, 2, 2, 3, 4), ncol = 2, nrow = 3, byrow = TRUE)

lotkaVolterra.trajectory <- trajectory(lotkaVolterra, y0 = y0, t.end = 10, parameters = c(2, 1, 3, 2), colour = rep("black", 3))

这是我得到的情节:

问题

当我尝试用我的等式做同样的事情时,向量 space 没有出现:

WalpeFun <- function(t, y, parameters) {
  x <- y[1]
  y <- y[2]
  k <- parameters[1]
  z <- parameters[2]
  w <- parameters[3]
  b <- parameters[4]
  d <- parameters[5]
  v <- parameters[6]
  a <- parameters[7]
  g <- parameters[8]
  l <- parameters[9]
  e <- parameters[10]
  dy <- numeric(2)
  dy[1] <- 2.5*(1-(x/k)^z)+g*l+w*e - b*(x*y/d^2+y^2)
  dy[2] <- 2.5 * (1 - (y/x + v)^a)
  list(dy)
}


Walpe.flowField <-flowField(WalpeFun, x.lim = c(0, 150), y.lim = c(-1, 50), parameters = c(120.73851, 0.51786, -0.75178, 0.00100, 1.00000, 500, 0.001, 0.01102, 320.995455, 5.582273) , points = 20, add = FALSE)

grid()

Walpe.nullclines <-nullclines(WalpeFun, x.lim = c(0, 150), y.lim = c(-1, 50), parameters = c(120.73851, 0.51786, -0.75178, 0.00100, 1.00000, 500, 0.001, 0.01102, 320.995455, 5.582273))

y0 <- matrix(c(8.2, 2), ncol = 2, nrow = 1, byrow = TRUE)

Walpe.trajectory <-trajectory(WalpeFun, y0 = y0, t.end = 100, parameters = c(120.73851, 0.51786, -0.75178, 0.00100, 1.00000, 500, 0.001, 0.01102, 320.995455, 5.582273),system = "two.dim", colour = "black")

我得到了这个非常不同的情节:

并得到以下错误:

Error in if ((dx[i, j] != 0) & (dy[i, j] != 0)) { : missing value where TRUE/FALSE needed

我不明白为什么不显示矢量,或者为什么缺少蓝色零斜线

从数学上讲,您的 x.lim 范围超出了函数可以取值的域。因为您的 dy[2] 表达式在其中一项的分母中有 x,所以函数在 x == 0 处爆炸,然后函数内部的 dy[]-矩阵中会有一个 NA代码。 (有一点含糊不清,因为你的 dy-object 是一个 2 元素向量,而查看代码时,计算存储在名为 dxdy 的二维矩阵中。 )

flowField  #look at the code
png()
Walpe.flowField <-flowField(WalpeFun, x.lim = c(0.01, 150), y.lim = c(-1, 50), parameters = c(120.73851, 0.51786, -0.75178, 0.00100, 1.00000, 500, 0.001, 0.01102, 320.995455, 5.582273) , points = 20, add = FALSE, system="two.dim")
Walpe.nullclines <-nullclines(WalpeFun, x.lim = c(0.01, 150), y.lim = c(-1, 50), parameters = c(120.73851, 0.51786, -0.75178, 0.00100, 1.00000, 500, 0.001, 0.01102, 320.995455, 5.582273))

y0 <- matrix(c(8.2, 2), ncol = 2, nrow = 1, byrow = TRUE)

Walpe.trajectory <-trajectory(WalpeFun, y0 = y0, t.end = 100, parameters = c(120.73851, 0.51786, -0.75178, 0.00100, 1.00000, 500, 0.001, 0.01102, 320.995455, 5.582273),system = "two.dim", colour = "black")
dev.off()

我不知道为什么 nullclines 没有出现,但我猜这个函数有一些我们都不理解的特性。