额外的参数必须位于元组中

Extra arguments must be in a tuple

提问人:SunnyDayXO 提问时间:3/1/2021 更新时间:3/1/2021 访问量:212

问:

我将尝试从图片中适应平等enter image description here

我的代码是

import numpy as np
import scipy.integrate as integrate
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

#define universal variables
def dH_dt(H, t=0):
    return np.array(((H1(t)-H0(t))**2)/sqrt((H0(t))**2*((H0(t))**2)))
t = np.linspace(0, 100, 10000) 
H0 = [0.0001]
H1 = [0.0001]
H, infodict = integrate.odeint(dH_dt, H0, H1, t, full_output=True)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(H[:,0], H[:,1])
plt.show()

我有这样的错误

 File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/scipy/integrate/odepack.py", line 241, in odeint
    output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
odepack.error: Extra arguments must be in a tuple.

你能说说我该如何解决它吗

python-3.x 同步 动态编程 相等

评论

2赞 Jaime Etxebarria 3/1/2021
这回答了你的问题吗?odepack.error:额外的参数必须位于元组中

答:

0赞 Jose Manuel de Frutos 3/1/2021 #1

在认为你必须尝试这样的事情时:

H, infodict = integrate.odeint(dH_dt, H0, H1, args=(t,), full_output=True)

你需要在里面添加一个逗号,这样python就知道它是一个元组。()