大家好我在我的ODE系列中遇到了一个问题。我有两个完全相同的方程式,但它们的答案却截然不同。我的方程式有不同答案的原因吗? 这两个方程是控制e和r的方程式。
library(sigmoid)
parameters <- c(
a = 0.032,
b = (9 / 140),
c = (5 / 1400),
d = (95 / 700),
k = 1 / 140,
i = 0.25,
# r = 0.2,
n = 6000000,
x = 0.5 ,
y = 0.25,
t = 1 / 180, # important in looking at the shape
u = 1 / 180, # important in looking at the shape
v = 1 / 180, # important in looking at the shape
p = 10,
s = 100,
g = 100
# e = .4,
#h = 1000
)
state <- c(
S = 5989900,
E = 0,
I = 0,
Q = 0,
D = 100,
B = 0,
C = 100,
Y = 100,
H = 100,
R = 10,
J = 10,
h = 100,
e = 0.1,
r = 0.1
)
# Function will transition between 0 and 1 when h and Q are approximately
equal
smooth.transition <- function(h, Q, tune = 0.01){
sigmoid((h/Q - 1)/tune)
}
Q <- 1
h <- seq(0.001, 5, by = 0.001)
plot(h/Q, j, type = "l")
# set up the equations
equation <- (function(t, state, parameters)
with(as.list(c(state, parameters)), {
# rate of change
dS <- (-(a * S * I) / n) - (((1 / r) * S * D) / n)
dE <- (a * S * I) / n + (((1 / r) * S * D) / n) - i * E
j <- smooth.transition(h, Q)
dI <- i * (j) * E - (e) * I - c * I - d * I
dQ <- (j) * (e) * I - b * Q - k * Q
dD <- d * I - r * D
dB <- b * Q + r * D
dC <- c * I + k * Q
dY <- p * (b * Q + r * D)
dR <- j*(1 - x - y) * (p * (b * Q + r * D)) - j*t * (R)
de <- j*t * (s / R)
dJ <- (y) * (p * (b * Q + r * D)) - v * (J)
dr <- v * (s / J)
dH <- (x) * (p * (b * Q + r * D)) - u * (H)
dh <- u * (H / g)
# return the rate of change
list(c(dS, dE, dI, dQ, dD, dB, dC, dY, dR, de, dJ, dr, dH, dh))
}))
#
# solve the equations for certain starting parameters
library(deSolve)
times <- seq(0, 200, by = 1)
out <-
ode(y = state,
times = times,
func = equation,
parms = parameters,
maxsteps = 1e5
)
# , method = "vode"
head(out)
tail(out)
# graph the results
par(oma = c(0, 0, 3, 0))
plot(out, xlab = "Time", ylab = "People")
#plot(out[, "X"], out[, "Z"], pch = ".")
mtext(outer = TRUE, side = 3, "Ebola Model",cex = 1.5
)
我在R,e,J和r的初始迭代中得到的是:
R: 10, 10.05540, 10.11050
e: 0.1, 59, 138
J: 10, 39, 79
r: 0.1, 0.105, 0.11
J和r表现得像我期望他们行动而R和e不行。任何人都可以在我的编码中看到问题。我认为我的数学很稳定。
答案 0 :(得分:0)
您已将参数定义为t
,解决方案中的时间也定义为t
。
答案 1 :(得分:0)
您返回的变化率的顺序与您最初定义状态变量的顺序不同。
CF
state <- c(
S = 5989900,
E = 0,
I = 0,
Q = 0,
D = 100,
B = 0,
C = 100,
Y = 100,
H = 100,
R = 10,
J = 10,
h = 100,
e = 0.1,
r = 0.1
)
带
list(c(dS, dE, dI, dQ, dD, dB, dC, dY, dR, de, dJ, dr, dH, dh))
返回列表应为:
list(c(dS, dE, dI, dQ, dD, dB, dC, dY, dH, dR, dJ, dh, de, dr))