Python Code
Python Code
# Experiment 1: Solve the S-wave Schrödinger equation for the ground state
and first excited state of H-atom.
# Coulombic potential
#2130210 Rajan Mishra
import numpy as np
import matplotlib.pyplot as plt
x0 = eval(input("Enter the initial value of x = "))
x1 = eval(input("Enter the final value of x = "))
y0 = eval(input("Enter the y at initial x = "))
y1 = eval(input("Enter the y at final x = "))
n = int(input("Enter the number of steps = "))
#step size
h = abs(x1-x0)/n
hcut = 1973
m = 0.511*10**6
e = 3.795
p = (hcut**2)/(2*m)
x = np.zeros(n+1)
for i in range (n+1):
x[i] = x0+i*h
print(x,"are the values of x")
potential = []
def a(l):
return ((-1)*p)/(h**2)
def b(l):
potential.append(- (e*e)/l)
return (2*p)/(h**2) - (e*e)/l #V = - e^2/r
def c(l):
return ((-1)*p)/(h**2)
def d(l):
return 0
A,B,C,D = [],[],[],[]
#Generating the tridiagonal matrix
for i in range (1,n):
#B[i] and D[i]
B.append(b(x[i]))
D.append(d(x[i]))
for j in range (1,n-1):
C.append(c(x[j]))
for k in range (2,n):
A.append(a(x[k]))
tridiag = np.zeros([n-1,n-1])
tridiag = tridiag + np.diag(B)+np.diag(C,1)+np.diag(A,-1)
print(tridiag,"is the tridiagonal matrix")
val,vec = np.linalg.eig(tridiag)
0
ar = []
for i in range (len(val)):
if val[i]<0:
ar.append(i)
#appending the index of negative energy eigenvalue
print("The Energy eigenvalues are = ",val[i])
for i in range (len(ar)):
arr = []
for j in range(len(vec)):
arr.append(vec[j][ar[i]])
plt.plot(x[1:n],arr,label = "E"+str(i))
plt.legend()
plt.xlabel("r")
plt.ylabel("u(r)")
plt.title("Coulomb Potential Wavefunction")
plt.grid()
plt.show()
Output:
Enter the initial value of x = 0
Enter the final value of x = 15
Enter the y at initial x = 0
Enter the y at final x = 0
Enter the number of steps = 1000
[ 0. 0.015 0.03 ... 14.97 14.985 15. ] are the values of x
[[ 32897.04264731 -16928.58882366 0. ... 0.
0. 0. ]
[-16928.58882366 33377.11014731 -16928.58882366 ... 0.
0. 0. ]
[ 0. -16928.58882366 33537.13264731 ... 0.
0. 0. ]
...
[ 0. 0. 0. ... 33856.21462324
-16928.58882366 0. ]
[ 0. 0. 0. ... -16928.58882366
33856.2155882 -16928.58882366]
[ 0. 0. 0. ... 0.
-16928.58882366 33856.21655122]] is the tridiagonal matrix
The Energy eigenvalues are = -13.611204733840399
The Energy eigenvalues are = -3.4033137382562537
The Energy eigenvalues are = -0.5990616129048474
The Energy eigenvalues are = -1.5055447780262636