【发布时间】:2016-04-08 18:43:12
【问题描述】:
我正在尝试编写一个程序,该程序将使用不同的方式(欧拉、龙格...)并使用内置函数 scipy.integrate.odeint 集成一个函数。
一切都好,我得到了正确的结果,但我还需要用结果创建一个图表,这就是一切都出错的时候。 对于 odeint 函数,我无法绘制图形。 这是我的代码和错误,希望有人能够帮助我。
def odeint(phi, t0tf, Y0, N):
T6=numpy.zeros((N+1))
T6[0]=t0tf[0]
h=(t0tf[1]-t0tf[0])/N
for i in range (N):
T6[i+1]=T6[i]+h
def f(t,x):
return phi(x,t)
Y6 = scipy.integrate.odeint(f,Y0,T6, full_output=True)
return Y6
Y6 = edo.odeint(phi, t0tf, Y0, N)
T6Y6 = numpy.hstack([Y6])
print("Solutions Scipy :")
print()
print(T6Y6)
print()
mpl.figure("Courbes")
mpl.plot(Y6[0:N,0],Y6[0:N,1],color="yellow",label="Isoda")
mpl.show()
错误是:
mpl.plot(Y6[0:N,0],Y6[0:N,1],color="yellow",label="Isoda")
TypeError: tuple indices must be integers, not tuple
提前致谢(PS:我是法国人,所以我的句子可能有点不稳定)
【问题讨论】:
-
能否请您包含完整的回溯并包含足够的信息,以便我们可以复制-粘贴-运行您的示例?
标签: numpy matplotlib graph tuples