Python odepack.error:额外参数必须在元组中
我的ode解算器有一些问题,我试图解决一个SEIR问题,我不断得到相同的错误,尽管我的代码非常相似。我的代码是:Python odepack.error:额外参数必须在元组中,python,pycharm,ode,Python,Pycharm,Ode,我的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,
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/firsttrunt/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:
args:tuple,可选
传递给函数的额外参数
另外,谷歌。对于单个参数,不要忘记在元组中添加逗号,例如
ret = odeint(deriv, y0, t, args=(singleArg,))
请参见此处了解单值元组
不幸的是,我没有足够的声誉发表评论。尝试用
args=(N1,B,a,d,g,z,M)
替换args=(N1,B,a,d,g,z,M)
。从文档中:args:tuple,传递给函数的可选额外参数。
感谢@Jean Françoisfare将答案说得很清楚,我很高兴。您找到了修复方法,但我想向您展示如何在格式和引用方面做出更好的回答。这个答案对于那些不得不使用python来使用特殊软件包,并且对python了解不多的人来说是很有用的。感谢@Jean Françoisfare,还有一个关于a和I1之间的方程式的小问题,没有*阻止代码运行