0

I am trying to solve the Schrodinger equtaion and wrote the program fine, still getting this error, I can't see the error in my code... also if there any other error in my code, please notify me..

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

the error is also attached

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

1 Answers1

1

When you run this script, are you running it from the command line? According to this extremely detailed answer, sys.argv[1] will return an out of range error unless there's a value being placed in a command argument.

To run it without error, you would need to run the following with the script in the current working directory:

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

Hope this helps!

Community
  • 1
  • 1
forking_frog
  • 136
  • 1
  • 1
    Was moreso referencing it because it contained a lot of information on the topic, and it wouldn't have made sense to repeat all of it. I'm not entirely sure it was downrate worthy, but to each their own. – forking_frog May 26 '16 at 04:41