getting "IndexError: list index out of range" with apparent no reason

getting "IndexError: list index out of range" with apparent no reason

我正在尝试求解薛定谔方程并且编写的程序很好,但仍然出现此错误,我看不到我的代码中的错误...另外,如果我的代码中有任何其他错误,请通知我..

""" 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

当您 运行 这个脚本时,您是从命令行 运行 安装它吗?根据此 extremely detailed answer,sys.argv[1] 将 return 超出范围错误,除非在命令参数中放置了一个值。

为了 运行 它没有错误,您需要 运行 在当前工作目录中使用脚本执行以下操作:

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

希望对您有所帮助!