Chapter 13: Boltzmann Distribution

Example Problem 13.1, Page Number 309

In [2]:
from math import factorial

#Variable Declaration

aH = 40         #Number of heads
N = 100         #Total events

#Calculations
aT = 100 - aH
We = factorial(N)/(factorial(aT)*factorial(aH))
Wexpected = factorial(N)/(factorial(N/2)*factorial(N/2))

#Results
print 'The observed weight %5.2e compared to %5.2e'%(We,Wexpected)
The observed weight 1.37e+28 compared to 1.01e+29

Example Problem 13.2, Page Number 310

In [6]:
from sympy import symbols, diff, log

#Varialbe declaration
n = 10000       #Total number of particles


#Calcualtions
def ster(i):
    return i*log(i)-i

n1, n2, n3, W = symbols('n1 n2 n3 W',positive=True)

n2 = 5000 - 2*n3
n1 = 10000 - n2 -n3
logW = ster(n) - ster(n1) - ster(n2) - ster(n3) 
fun = diff(logW, n3)
dfun = diff(fun, n3)
x0 = 10.0
err = 1.0
while err>0.001:
    f = fun.subs(n3,x0)
    df = dfun.subs(n3,x0)
    xnew = x0 - f/df
    err = abs(x0-xnew)/x0
    x0 = xnew

x0 = int(x0)
N2 = n2.subs(n3,x0)
N3 = x0
n1 = n1.subs(n3,x0)
N1 = n1.subs(n2,N2)
lnW = logW.subs(n3,N3)

#Results
print 'At maximum value of ln(W)'
print 'Values of N1 : %4d, N2: %4d and N3: %4d '%(N1, N2,N3)
print 'Maximum value of ln(W)= %6d'%lnW
At maximum value of ln(W)
Values of N1 : 6162, N2: 2676 and N3: 1162 
Maximum value of ln(W)=   9012

Example Problem 13.3, Page Number 314

In [8]:
#Variable Declaration
p0 = 0.633        #Probabilities of Energy level 1,2,3 
p1 = 0.233
p2 = 0.086

#Calculation
p4 = 1. -(p0+p1+p2)

#Results
print 'Probability of finding an oscillator at energy level of n>3 is %4.3f i.e.%4.1f percent'%(p4,p4*100)
Probability of finding an oscillator at energy level of n>3 is 0.048 i.e. 4.8 percent

Example Problem 13.4, Page Number 315

In [10]:
#Variable Declaration
p0 = 0.394        #Probabilities of Energy level 1,2,3 
p1by2 = 0.239
p2 = 0.145

#Calculation
p4 = 1. -(p0+p1by2+p2)

#Results
print 'Probability of finding an oscillator at energy level of n>3 is %4.3f'%(p4)
Probability of finding an oscillator at energy level of n>3 is 0.222

Example Problem 13.5, Page Number 321

In [16]:
from math import exp

#Variable Declaration
I2 = 208         #Vibrational frequency, cm-1 
T = 298          #Molecular Temperature, K
c = 3.00e10      #speed of light, cm/s
h = 6.626e-34    #Planks constant, J/K
k = 1.38e-23     #Boltzman constant, J/K
#Calculation
q = 1./(1.-exp(-h*c*I2/(k*T)))
p2 = exp(-2*h*c*I2/(k*T))/q

#Results
print 'Partition function is %4.3f'%(q)
print 'Probability of occupying the second vibrational state n=2 is %4.3f'%(p2)
Partition function is 1.577
Probability of occupying the second vibrational state n=2 is 0.085

Example Problem 13.6, Page Number 322

In [18]:
#Variable Declaration
B = 1.45         #Magnetic field streangth, Teslas 
T = 298          #Molecular Temperature, K
c = 3.00e10      #speed of light, cm/s
h = 6.626e-34    #Planks constant, J/K
k = 1.38e-23     #Boltzman constant, J/K 
gnbn = 2.82e-26  #J/T
#Calculation
ahpbyahm = exp(-gnbn*B/(k*T))

#Results
print 'Occupation Number is %7.6f'%(ahpbyahm)
Occupation Number is 0.999990