Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

import numpy as np

import matplotlib.pyplot as plt


from scipy.integrate import odeint
from scipy.optimize import brentq

from scipy.optimize import root


zo = 15.0
#functions for even n
def fo(z):

global zo
if((z==0)or((z%(np.pi/2))==0)):
return 0
else:
return -1/np.tan(z)-np.sqrt((zo/z)**2-1)

#functions for odd n


def fe(z):

global zo
if((z==0)or(z%(np.pi))==0):# to avoid devide by zero at tan(0,270,...)
return 0
else:
return np.tan(z)- np.sqrt((zo/z)**2-1)

z=np.linspace(0.0001,6*np.pi,1000)

f_yo = np.zeros(len(z))
f_ye = np.zeros(len(z))

for i in range(len(z)):
resulto = fo(z[i])

f_yo[i]=resulto

resulte=fe(z[i])
f_ye[i]=resulte
#obtaining the sign of the function

se=np.sign(f_ye)
print('the values of energies for odd value of n:')
for i in range(len(se)-1):
if se[i]+se[i+1]==0:
#if the sum of the two consecutive element is zero.change the sign of the function
zero=brentq(fe,z[i],z[i+1])
print (zero)

print('the values of energies for even value of n:')


s=np.sign(f_yo)

for i in range (len(s)-1):


if s[i]+s[i+1]==0:
zero=brentq(fo,z[i],z[i+1])
print (zero)
import math as mt
E=np.linspace(0,6*np.pi,1000)
y1=np.tan(E)
y3= -1.0/np.tan(E)
y2=np.sqrt((15/E)**2-1.0)
plt.ylim(0,15)
plt.plot(E,y1,label="tan(z)")
plt.plot(E,y2,label='sqrt((15/E)**2 -1.0)')
plt.plot(E,y3,label='cotZ')
plt.xlabel('z')
plt.grid()
plt.legend()
plt.show()
the values of energies for odd value of n:
1.4724731069952235
1.5707963267933058
4.413720365472234
4.712388980383839
7.3424678255209255
7.853981633975665
10.243819962159803
10.99557428756302
13.078146053531126
14.137166941155217
the values of energies for even value of n:
2.944040804484885
3.1415926535915086
5.880354997934257
6.28318530718017
8.798005560948688
9.424777960770516
11.674424811481892
12.566370614357865
14.416907317160316

You might also like