#Variable declaration
L= 1.0; #assuming Length L of box to be 1, this would not affect the probability
x1=0.45; #lower bound
x2=0.55; #upper bound
from scipy.integrate import quad
import math
#Calculation
def f(x):
y=(math.sin(n*(math.pi)*x))**2
return(y)
n=1.0;
I1=quad(f,x1,x2) #for ground state
P1=(2/L*I1[0])
n=2.0;
I2=quad(f,x1,x2) #for ground state
P2=(2/L*I2[0])
#Result
print"The probability n ground state is: ",round(P1,3),"=",round(P1,3)*100,"percent"
print"The probability in first excited state is: ",round(P2,4),"=",round(P2,4)*100,"percent"
#Variable declaration
#Part (a)
E1= 1.0 #energy of first electron, eV
E2= 2.0 #energy of second electron, eV
Eb= 10.0 #height of barrier, eV
Wb= 0.50 #width of barrier, nm
Wb= Wb* 10**(-9) #converting to m
hbar= 1.054*10**(-34) #reduced Planck's conctaant, J.s
Me= 9.1*10**(-31) #mass of electron, kg
e= 1.6*10**(-19) #charge of an electron, J/eV
import math
#Calculation
k2= (math.sqrt(2*(Me)*(Eb-E1)*(e)))/(hbar) #for 1.0 eV e-, m**(-1)
k1= (math.sqrt(2*Me*(Eb-E2)*e))/hbar #for first electron, m**(-1)
T1= math.exp((-2)*k2*Wb) #transmission probability for first electron
T2= math.exp((-2)*k1*Wb) #for second electron
print"(A.)\nTransmission probability for electrons with energy 1.0 eV is:%.2g"%T1
print"Transmission probability for electrons with energy 2.0 eV is: %.2g"%T2
#Part (b)
Wb= Wb*2; #Barrier width doubled
T11= math.exp((-2)*k2*Wb) # changed transmission probability for first electron
T22= math.exp((-2)*k1*Wb) #for second electron
#Result
print"\n\n(B.):After the barrier width is doubled:\n"
print"Transmission probability for electrons with energy 1.0 eV is:%.2g"%T11
print"Transmission probability for electrons with energy 2.0 eV is: %.2g"%T22
print"\n\nNOTE:Calculation mistake in book in the calculation of k2,\nit is wrongly written as 1.6e+10,\nTHAT's Why a change in final answer"