2017-06-01 11 views
0

私は、レーザー速度方程式(常微分方程式1次)をPython(odeint)で解くための小さなプログラムに問題があります。エラー:インデックス2は、軸1のサイズが1の範囲外です。

私はプログラムを実行すると、エラーが常に現れる:

index 2 is out of bounds for axis 0 with size 1 

方程式は正しいです。私はこのエラーの意味を知らない。

誰でもこの意味と解決方法を説明できますか?

def Rate(y,t): 
    D = y[0] 
    P = y[1] 
    w = 1.3 
    F = 0.0001 
    R = 90 
    dD_dt= w - D*P -D 
    dP_dt= R*D*P - R*P +F*D 
    dydt = [dD_dt,dP_dt] 
    return dydt 
    y0=0 
    t=np.arange(0,100,0.01) 
    sol=odeint(Rate,y0,t) 
    plt.plot(t,sol[:,0],'b',label='normalized inversion(t)') 
    plt.plot(t,sol[:,1],'g',label='normalized photon density(t)') 
    plt.legend() 
    plt.xlabel('t') 
    plt.grid() 
    plt.show() 

とエラーになります:

IndexError        Traceback (most recent call last) 
    <ipython-input-20-50f3d07b9161> in <module>() 
    ----> 1 sol=odeint(Rate,y0,t) 

    C:\Users\asem\Anaconda2\lib\site-packages\scipy\integrate\odepack.pyc in 
    odeint(func, y0, t, args, Dfun, col_deriv, full_output, ml, mu, rtol, atol, 
    tcrit, h0, hmax, hmin, ixpr, mxstep, mxhnil, mxordn, mxords, printmessg) 
    213  output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu, 
    214        full_output, rtol, atol, tcrit, h0, hmax, 
    hmin, 
    --> 215        ixpr, mxstep, mxhnil, mxordn, mxords) 
    216  if output[-1] < 0: 
    217   warning_msg = _msgs[output[-1]] + " Run with full_output = 1 to 
    get quantitative information." 

    <ipython-input-18-2f25cf16efde> in Rate(y, t) 
     1 def Rate(y,t): 
     2  D =y[0] 
     ----> 3  P =y[2] 
     4  w = 1.3 
     5  F = 0.0001 

     IndexError: index 2 is out of bounds for axis 0 with size 1 

答えて

0

は、あなたが本当に持っているものを見るために行2と3の間print yを試してみてください。

これは、yに1つの要素しかないことを意味します。リストに1つしかない場合、要素2(3番目の要素)を取得することはできません。

あなたのコードとエラーメッセージは一致しませんのでご注意ください(y [1]対y [2])。

関連する問題