odepack.error:额外的参数必须在元组中

时间:2017-08-17 12:04:29

标签: 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, 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:额外的参数必须在元组中

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

尝试更换:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" id="optional">Additional box</a>
<div id="popup" style="position: absolute; top: 50%; transform: translateY(-50%); width: 500px; left: 50%; margin-left: -250px; background: #000; color: #fff; display: none;">
  <p>Params <button type="button" id="close">x</button></p>
  <div style="position: relative; overflow: hidden; width: 173px;">
    <button type="button" id="incrementer" style="position: absolute; right: 0; top: 0; height: 21px; width: 21px; border: 0;">+</button>
    <button type="button" id="decrementer" style="position: absolute; right: 21px; top: 0; height: 21px; width: 21px; border: 0;">-</button>
    <input class="param1" type="text" placeholder="0" value="" />
  </div>
  <button type="button" id="generate">Generate</button>
  <div id="example"></div>

用这个:

  ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)

从scipy documentation

  

args:元组,可选

     

传递给函数的额外参数。

此外,谷歌differences b/w list and tuple

答案 1 :(得分:1)

对于单个参数,请不要忘记在元组中添加逗号,例如

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
}

有关单值元组的信息,请参见https://www.tutorialspoint.com/python/python_tuples.htm

不幸的是,我没有足够的声誉来发表评论。