odepack.error: Extra arguments must be in a tuple
odepack.error: Extra arguments must be in a tuple
我的 ode 求解器有一些问题,我正在尝试解决 SEIR 问题,尽管我的代码基于非常相似的代码,但我不断遇到相同的错误。我的代码是:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Total population, N.
N1 = 55600
# Initial number of infected and recovered individuals, I0 and R0.
I10, R10, E10 = 1, 0, 0
# Everyone else, S0, is susceptible to infection initially.
S10 = N1 - I10 - R10 - E10
# parameters
B = 0.05
a = 0.000001
d = 0.0167
g = 0.0167
z = 0.0167
M = 100000
# A grid of time points (in months)
t = np.linspace(0, 160, 160)
# The SIR model differential equations.
def deriv(y, t, N1, B, a, d, g, z, M):
S1, E1, I1, R1 = y
dS1dt = B*N1 + d*(R1) - S1/N1 * (M*a(I1))
dE1dt = S1/N1 * M*a(I1) - g * E1
dI1dt = g * E1 - z * I1
dR1dt = z * I1 - d * R1
return dS1dt, dE1dt, dI1dt, dR1dt
# Initial conditions vector
y0 = S10, E10, I10, R10
# Integrate the SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M])
S1, E1, I1, R1 = ret.T
我不断收到错误消息:
文件 "C:/Users/Angus/PycharmProjects/firstAttempt/bugfinder.py",第 44 行,
在
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)
文件 "C:\Python36\lib\site-packages\scipy\integrate\odepack.py",第 215 行,在 odeint 中
ixpr、mxstep、mxhnil、mxordn、mxords)
odepack.error: 额外的参数必须在元组中
如有任何帮助,我们将不胜感激!
尝试替换:
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)
有了这个:
ret = odeint(deriv, y0, t, args=(N1, B, a, d, g, z, M))
来自scipy documentation:
args : tuple, optional
Extra arguments to pass to function.
此外,google differences b/w list and tuple。
对于单个参数,不要忘记在元组中添加逗号,例如
ret = odeint(deriv, y0, t, args=(singleArg,))
请参阅此处 https://www.tutorialspoint.com/python/python_tuples.htm 了解单值元组。
很遗憾,我没有足够的声誉来发表评论。
我的 ode 求解器有一些问题,我正在尝试解决 SEIR 问题,尽管我的代码基于非常相似的代码,但我不断遇到相同的错误。我的代码是:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Total population, N.
N1 = 55600
# Initial number of infected and recovered individuals, I0 and R0.
I10, R10, E10 = 1, 0, 0
# Everyone else, S0, is susceptible to infection initially.
S10 = N1 - I10 - R10 - E10
# parameters
B = 0.05
a = 0.000001
d = 0.0167
g = 0.0167
z = 0.0167
M = 100000
# A grid of time points (in months)
t = np.linspace(0, 160, 160)
# The SIR model differential equations.
def deriv(y, t, N1, B, a, d, g, z, M):
S1, E1, I1, R1 = y
dS1dt = B*N1 + d*(R1) - S1/N1 * (M*a(I1))
dE1dt = S1/N1 * M*a(I1) - g * E1
dI1dt = g * E1 - z * I1
dR1dt = z * I1 - d * R1
return dS1dt, dE1dt, dI1dt, dR1dt
# Initial conditions vector
y0 = S10, E10, I10, R10
# Integrate the SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M])
S1, E1, I1, R1 = ret.T
我不断收到错误消息:
文件 "C:/Users/Angus/PycharmProjects/firstAttempt/bugfinder.py",第 44 行, 在
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)
文件 "C:\Python36\lib\site-packages\scipy\integrate\odepack.py",第 215 行,在 odeint 中 ixpr、mxstep、mxhnil、mxordn、mxords) odepack.error: 额外的参数必须在元组中
如有任何帮助,我们将不胜感激!
尝试替换:
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)
有了这个:
ret = odeint(deriv, y0, t, args=(N1, B, a, d, g, z, M))
来自scipy documentation:
args : tuple, optional
Extra arguments to pass to function.
此外,google differences b/w list and tuple。
对于单个参数,不要忘记在元组中添加逗号,例如
ret = odeint(deriv, y0, t, args=(singleArg,))
请参阅此处 https://www.tutorialspoint.com/python/python_tuples.htm 了解单值元组。
很遗憾,我没有足够的声誉来发表评论。