2016-05-26 9 views
0

私はSchrodinger equtaionを解決しようとしていますが、まだこのエラーが発生していますが、私のコードでエラーが表示されません...私のコード内の他の誤りがあれば、私に連絡してください。..「IndexError:リストインデックスが範囲外です」

""" SEsolve.py....................... 
uses shootingmethod t find even-parity solutions to the inite square well. Takes two guesse of energy from the command line, finds a bracketed energy eigenalue E, and plots the corresponding waavefunctions.. 
h_bar, m and L are all taken to be 1 

the parameter b is the pointin units of L at which to check if the wavefunction dierges, b must be greater than 1 , of course... 

Solutions are not normalized""" 

from pylab import * 
from scipy.integrate import odeint 
from scipy.optimize import brentq 
import sys 

b = 2.0 
V0 = 20.0      # potenial outside square well 
steps = 1000 
E = 0.0       # global variable, changed by finlvalue 

def V(x):      #potential inwhich the partice exists 
    if x < 1.0: 
     return 0 
    else: 
     return V0  # definition of square well 

def SE(y,x): 
    """ returns derivatives for the 1-D TISE, for use in oeint, requires globl value to be set esewhere, Note that we are using x stime here..""" 
    g0 = y[1] 
    g1 = -2.0 * (E-V(x)) * y[0] 
    return array ([g0, g1]) 

def Final_Value(energy): 
    """calculates wave funcion for thisvalue of E, and returns the value ofpsi at point b to check divergence""" 
    global y 
    global E 
    E = energy 
    y = odeint (SE, y0, x) 
    return y[-1,0] 


y = zeros ([steps, 2]) 
y0 = array ([1.0, 0.0]) 
x = linspace (0,b, steps) 

E1 =float (sys.argv[1]) 
E2 = float(sys.argv[2]) 

answer = brentq (Final_Value, E1, E2) 


print "Eigenvalue found at E = %0.8f" % answer 

plot (x, y[:,0]) 
xlabel("poition (units of L)") 
show() 

エラーも

Traceback (most recent call last): 
    File "PDE.py", line 44, in <module> 
    E1 =float (sys.argv[1]) 
IndexError: list index out of range 

答えて

0

このスクリプトを実行すると、コマンドラインからそれを実行しているの?取り付けられていますか。このextremely detailed answerによれば、sys.argv [1]は、コマンド引数に値が置かれていない限り、範囲外のエラーを返します。エラーなしでそれを実行するには

、あなたは現在の作業ディレクトリにスクリプトで次のコマンドを実行する必要があります:

python PDE.py (your first float value) (your second float value)

・ホープ、このことができます!

+0

まだコメントすることはできませんので、直接お答えすることができます。 –

+0

トピックに多くの情報が含まれていたため、それを参照していましたが、すべてを繰り返すのは意味がありませんでした。私はそれが価値があるとは思えないが、それぞれ自分のものに落ちる。 –

関連する問題