0% found this document useful (0 votes)
15 views12 pages

Statistical Mechanics Prishat

Python code for stastical physics for undergraduate syllabus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Statistical Mechanics Prishat

Python code for stastical physics for undergraduate syllabus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

#Plots mean occupation numbers of MB, BE, FD distribution

Input:

import numpy as np

from scipy.constants import h, k, e

import scipy.constants as spc

import matplotlib.pyplot as plt

print(h,k,e)

bke = k/e

print(bke)

xef = np.linspace(-4,4,201)

shift = 1e-6

xeb = np.linspace(0 + shift, 4 + shift,101)

def fdist (energy, temperature, signature = 0, chempot = 0) :

x = (energy - chempot)/temperature/bke

d = np.exp(x) + signature

return 1/d

def fdist_scaled(x, signature = 0):

d = np.exp(x) + signature

return 1/d

temp = 300

plt.plot(xef,fdist_scaled(xef), label= "MB")

plt.plot(xeb,fdist_scaled(xeb,-1), label= "BE")

plt.plot(xef,fdist_scaled(xef,1), label= "FD")

plt.legend()

plt.ylim(0,3)
plt.xlim(-4,4)

plt.xlabel(r"$(E - \mu)/kT$",fontsize = 14)

plt.ylabel(r"$\langle n_E \rangle$",fontsize = 14)

plt.title (r"Compasrison of mean occupation numbers at $\mu = 0$")

plt.show()

Output:

(6.62607015e-34, 1.380649e-23, 1.602176634e-19)

8.617333262145179e-05
2. #Fermi Dirac distribition at different temperatures

Input:

import numpy as np

from scipy.constants import h, k,e

import scipy.constants as spc

import matplotlib.pyplot as plt

bke = k/e

engf = np.linspace(-0.5,0.5 ,201)

T = np.array([100,400,800])

print (T/bke)

def fdist (energy, temperature, signature = 0, chempot = 0) :

x = (energy - chempot)/temperature/bke

d = np.exp(x) + signature

return 1/d

for l in T :

plt.plot(engf,fdist (engf,l,1),label=r"$T={l}$".format(l=l))

plt.xlabel(r"$E$ (eV)",fontsize = 14)

plt.ylabel(r"$\langle n_E \rangle$",fontsize = 14)

plt.title (r"Fermi Dirac Distribition, $\mu = 0$")

plt.legend(loc='best')

plt.show()
Output:
3. #Maxwell Boltzmann distribution at different temperatures

Input:

import numpy as np

from scipy.constants import h, k,e

import scipy.constants as spc

import matplotlib.pyplot as plt

bke = k/e

engf = np.linspace(-0.5,0.5 ,201)

T = np.array([100,400,800])

print (T/bke)

def fdist (energy, temperature, signature = 0, chempot = 0) :

x = (energy - chempot)/temperature/bke

d = np.exp(x) + signature

return 1/d

for l in T :

plt.plot(engf,fdist (engf,l,0),label=r"$T={l}$".format(l=l))

plt.xlabel(r"$E$ (eV)",fontsize = 14)

plt.ylabel(r"$\langle n_E \rangle$",fontsize = 14)

plt.title (r"Maxwell Boltzmann Distribition, $\mu = 0$")

plt.ylim(0,1.5)

plt.xlim(-.01,0.3)

plt.legend(loc='best')

plt.show()
Output:
4. #Bose Eintein distribution

Input:

import numpy as np

from scipy.constants import h, k,e

import scipy.constants as spc

import matplotlib.pyplot as plt

bke = k/e

shift = 1e-6

eng = np.linspace(0 + shift,0.5 + shift,201)

T = np.array([100,400,800])

def fdist (energy, temperature, signature = 0, chempot = 0) :

x = (energy - chempot)/temperature/bke

d = np.exp(x) + signature

return 1/d

for l in T :

plt.plot(eng,fdist (eng,l,-1),label=r"$T={l}$".format(l=l))

plt.xlabel(r"$E$ (eV)",fontsize = 14)

plt.ylabel(r"$\langle n_E \rangle$",fontsize = 14)

plt.title (r"Bose Eintein distribution, $\mu = 0$")

plt.ylim(0,1.5)

plt.xlim(-.01,0.3)

plt.legend(loc='best')

plt.show()
Output:
5. #Specific heat (Debye model)

Input:

import numpy as np

import matplotlib.pyplot as plt

from scipy.integrate import quad

def debyescalar (T, dT) :

xd = dT/T

bose = lambda x : 1/(np.exp(x) - 1)

xil = bose(xd)

dkernel = lambda xi : (np.log(1 + 1/xi))**4

res, er = quad(dkernel,xil, np.inf, epsrel = 1e-7)

pre = 3/xd**3

return pre*res

debye = np.vectorize(debyescalar)

debyetemp = [428,105,2230]

debyemat= ["Al","Pb","C"]

conv = (np.pi/6)**(1/3)

print (conv)

#eintemp = conv*debyetemp

temp = np.linspace(5,1000, num = 100, dtype=float)

for t in debyetemp :

i = debyetemp.index(t)

el = debyemat[i]

plt.plot(temp,debye(temp,t),\

label=r"{0}, $\theta_D$ = {1} K".format(el,t))

plt.axhline(y = 1.01, ls='--', color='b', label="Dulong-Petit")

plt.ylabel(r"$C_v/(3Nk_B)$",fontsize=14)
plt.xlabel(r"$T$ (K)",fontsize = 14)

plt.title(r"$C_v$ (Debye Model)", fontsize = 16)

plt.legend()

plt.show()

Output:
6. #Two level system (Energy)

Input:

import numpy as np

from scipy.misc import derivative

import matplotlib.pyplot as plt

N = 1000 # number of particles

def sppf (w) :

return 2*np.cosh(1/w)

def pf(w) :

return sppf(w)**N

def lsppf (w) :

return np.log(sppf(w))

def U (w):

# calculates U/N\epsilon

uw = w*w * derivative(lsppf, w, dx = .001, n = 1)

return uw

x = np.linspace(0.1, 6, num = 100, dtype=float) #scaled temperature

nd = (10, 100, 1000)

# Internal Energy/N\epsilon

plt.plot(x, U (x))

plt.axhline(y = 0, ls = "--")

plt.xlabel(r"$kT/\epsilon$", fontsize = 14)

plt.ylabel(r"$U/(N\epsilon)$",fontsize = 14)
plt.title("Energy of two level system")

plt.show()

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy