2016-04-08 37 views
0

我试图编写一个程序,它将使用不同的方式(欧拉,Runge ...)集成一个函数并使用内置函数scipy.integrate.odeint。元组索引必须是整数不是元组,matplot

一切和我得到正确的结果,但我也需要创建一个图形的结果,这就是当一切都出错了。 对于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:我是法国人,所以我的句子可能是有点不稳)

+0

你能否包括完整的回溯,并包含足够的信息,我们可以复制粘贴 - 运行你的例子? – tacaswell

回答

0

Y6似乎是一个元组,你是以不正确的方式呼叫。这是很难指出究竟什么是错的,因为你没有提供的数据,但下面的例子说明了如何从一个tuple来电元素:

y = ((1,2,3,4,5),) 
print('This one works: ',y[0][1:]) 
print(y[1:,0]) 

,结果是这样的:

This one works: (2, 3, 4, 5) 
Traceback (most recent call last): 
    File "E:\armatita\stackoverflow\test.py", line 9, in <module> 
    print(y[1:,0]) 
TypeError: tuple indices must be integers, not tuple 
相关问题