# 15: Statistical mechanics¶

## Example number 15.1, Page number 341¶

In :
#importing modules
import math
import fractions
from __future__ import division

#Variable declaration
n = 10;       #number of identical coins
r1 = 10;       #number of heads in 1st case
r2 = 5;        #number of heads in 2nd case
r3 = 3;        #number of heads in 3rd case

#Calculation
P10_0 = math.factorial(n)/(math.factorial(r1)*math.factorial(n-r1)*(2**n));        #probability of getting all heads
P10_0 = fractions.Fraction(P10_0);        #probability in fraction
P5_5 = math.factorial(n)/(math.factorial(r2)*math.factorial(n-r2)*(2**n));         #probability of getting 5 heads and 5 tails
P5_5 = fractions.Fraction(P5_5);          #probability in fraction
P3_7 = math.factorial(n)/(math.factorial(r3)*math.factorial(n-r3)*(2**n));         #probability of getting 3 heads and 7 tails
P3_7 = fractions.Fraction(P3_7);          #probability in fraction
Pmax = math.factorial(n)/(((math.factorial(n/2))**2)*(2**n))            #most probable combination
Pmax = fractions.Fraction(Pmax);          #probability in fraction
Pmin = 1/(2**n);              #least probable combination
Pmin = fractions.Fraction(Pmin);            #probability in fraction

#Result
print "probability of getting all heads is",P10_0
print "probability of getting 5 heads and 5 tails is",P5_5
print "probability of getting 3 heads and 7 tails is",P3_7
print "most probable combination is",Pmax
print "least probable combination is",Pmin

probability of getting all heads is 1/1024
probability of getting 5 heads and 5 tails is 63/256
probability of getting 3 heads and 7 tails is 15/128
most probable combination is 63/256
least probable combination is 1/1024


## Example number 15.2, Page number 342¶

In :
#importing modules
import math
import fractions
from __future__ import division

#Variable declaration
n = 3;          #number of particles
N = 2;          #number of compartments
ms = 4;         #number of macrostates
n1_03 = 0;        #value of n1 for (0,3)
n2_03 = 3;        #value of n2 for (0,3)
n1_12 = 1;        #value of n1 for (1,2)
n2_12 = 2;        #value of n2 for (1,2)
n1_21 = 2;        #value of n1 for (2,1)
n2_21 = 1;        #value of n2 for (2,1)
n1_30 = 3;        #value of n1 for (3,0)
n2_30 = 0;        #value of n2 for (3,0)

#Calculation
#the macrostates are (n1,n2) = [(0,3),(1,2),(2,1),(3,0)]
ms_03 = math.factorial(n)/(math.factorial(n1_03)*math.factorial(n2_03));          #number of microstates in the macrostate (0,3)
mis_03 = "(0,xyz)";                   #microstates in the macrostate (0,3)
ms_12 = math.factorial(n)/(math.factorial(n1_12)*math.factorial(n2_12));          #number of microstates in the macrostate (1,2)
mis_12 = "[(x,yz),(y,zx),(z,xy)]";             #microstates in the macrostate (1,2)
ms_21 = math.factorial(n)/(math.factorial(n1_21)*math.factorial(n2_21));          #number of microstates in the macrostate (2,1)
mis_21 = "[(xy,z),(yz,x),(zx,y)]";             #microstates in the macrostate (2,1)
ms_30 = math.factorial(n)/(math.factorial(n1_30)*math.factorial(n2_30));          #number of microstates in the macrostate (3,0)
mis_30 = "(xyz,0)";                   #microstates in the macrostate (3,0)
tms = N**n;            #total number of microstates
mis = "[(0,xxx),(x,xx),(xx,x),(xxx,0)]";        #the microstates when particles are indistinguishable

#Result
print "number of microstates in the macrostate (0,3) is",ms_03,"that is",mis_03
print "number of microstates in the macrostate (1,2) is",ms_12,"that is",mis_12
print "number of microstates in the macrostate (2,1) is",ms_21,"that is",mis_21
print "number of microstates in the macrostate (3,0) is",ms_30,"that is",mis_30
print "total number of microstates is",tms
print "the microstates when particles are indistinguishable are",mis

number of microstates in the macrostate (0,3) is 1.0 that is (0,xyz)
number of microstates in the macrostate (1,2) is 3.0 that is [(x,yz),(y,zx),(z,xy)]
number of microstates in the macrostate (2,1) is 3.0 that is [(xy,z),(yz,x),(zx,y)]
number of microstates in the macrostate (3,0) is 1.0 that is (xyz,0)
total number of microstates is 8
the microstates when particles are indistinguishable are [(0,xxx),(x,xx),(xx,x),(xxx,0)]


## Example number 15.3, Page number 343¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
n1 = 4;       #1st group of particles
n2 = 2;       #2nd group of particles
n3 = 8;       #3rd group of particles
n4 = 6;       #4th group of particles
n5 = 5;       #5th group of particles
v1 = 1;       #speed of 1st group of particles
v2 = 2;       #speed of 2nd group of particles
v3 = 3;       #speed of 3rd group of particles
v4 = 4;       #speed of 4th group of particles
v5 = 5;       #speed of 5th group of particles

#Calculation
vbar = ((n1*v1)+(n2*v2)+(n3*v3)+(n4*v4)+(n5*v5))/(n1+n2+n3+n4+n5);         #average speed(m/sec)
vsquarebar = ((v1*(n1**2))+(v2*(n2**2))+(v3*(n3**2))+(v4*(n4**2))+(v5*(n5**2)))/(n1+n2+n3+n4+n5);        #mean square speed
rms = math.sqrt(vsquarebar);                #root mean square speed(m/sec)
rms = math.ceil(rms*10**3)/10**3;   #rounding off to 3 decimals

#Result
print "average speed is",vbar,"m/sec"
print "root mean square speed is",rms,"m/sec"

average speed is 3.24 m/sec
root mean square speed is 4.405 m/sec


## Example number 15.4, Page number 344¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
t = 27;         #temperature(C)
M = 14;         #mass of nitrogen(gm)
kb = 1.38*10**-23;     #boltzmann constant

#Calculation
T = t+273;      #temperature(K)
M = M*10**-3;       #mass of nitrogen(kg)
vmp = math.sqrt(2*kb*T*a/M);             #most probable speed of nitrogen(m/sec)
vmp = math.ceil(vmp*10)/10;   #rounding off to 1 decimal

#Result
print "most probable speed of nitrogen is",vmp,"m/sec"
print "answer given in the book is wrong"

most probable speed of nitrogen is 596.7 m/sec
answer given in the book is wrong


## Example number 15.5, Page number 344¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
t = 37;       #normal temperature of human body(C)
b = 2.898*10**-3;      #constant of proportionality(mK)

#Calculation
T = t+273;         #normal temperature of human body(K)
lamda_m = b/T;      #wavelength for maximum energy radiation(m)
lamda_m = lamda_m*10**10;         #wavelength for maximum energy radiation(angstrom)

#Result
print "wavelength for maximum energy radiation is",int(lamda_m),"angstrom"
print "answer given in the book is wrong"

wavelength for maximum energy radiation is 93483 angstrom
answer given in the book is wrong


## Example number 15.6, Page number 344¶

In :
#importing modules
import math
from __future__ import division

#Variable declaration
kb = 1.38*10**-23;     #boltzmann constant
thetaE = 230;        #einstein's temperature(K)
h = 6.63*10**-34;          #planck's constant(m**2 kg/s)

#Calculation
newE = kb*thetaE/h;         #einstein's frequency(per sec)

#Result
print "einstein's frequency is",round(newE/1e+12,2),"*10**12 per sec"

einstein's frequency is 4.79 *10**12 per sec