BSC 6th Sem Python LNB

 avatarAnamitra
Public2 years ago2 Snippets
Search
Language
Sort by
📅 Created Date
Order

Code 02

python2 years ago
MB, BE & FD Statistics
import numpy as np
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'] = (18, 12)

E = np.linspace(-0.5, 0.5, 1001)   # Energy Range
T = np.linspace(100, 1100, 6)   # Temperature In Kelvin
e = 1.6e-19   # Electronic Charge
K = 1.38e-23   # Boltzmann Constant
U = 0   # Chemical Potential
a = -1   # Parameter for adjusting the distribution functions

# Function to calculate the distribution function f(E)
def f(T,a):
    return 1/((np.exp(((E-U)*e)/(K*T)))+a)

# Loop to plot the Bose-Einstein, Maxwell-Boltzmann, and Fermi-Dirac distributions
title = ['BE Distribution', 'MB Distribution', 'FD Distribution']
while a<=1:
    plt.subplot(2,2,a+2)
    for i in range(len(T)):
        plt.plot(E, f(T[i],a), label=f'T = {T[i]} K')
        plt.ylim(0,4)
        plt.legend(title='Temperature', fontsize=14)
        plt.xlabel('Energy(eV)', fontsize=14)
        plt.ylabel(' Value Of The Distribution Function [f(E)]', fontsize=14)
    plt.title(title[a+1])
    a = a+1

# Subplot to compare all three distribution functions at 700 K
label = ['BE Distribution', 'MB Distribution', 'FD Distribution']
plt.subplot(2,2,4)
for i in [-1,0,1]:
    plt.plot(E,f(700,i), label=label[i+1])
    plt.ylim(0,4)
    plt.legend(title='Distribution Laws', fontsize=14)
    plt.xlabel('Energy(eV)', fontsize=14)
    plt.ylabel(' Value Of The Distribution Function [f(E)]', fontsize=14)
    plt.title('Comparison Of These Three Distribution Functions At 700K', fontsize=16)
plt.show()

Code 01

python2 years ago
Plot Planck's Law For Black Body Radiation And Compare It With Raleigh-Jeans Law At High And Low Temperature
import numpy as np
import scipy.constants as const
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'] = (12, 10)

pi = const.pi  # Value Of Pi
h = const.h  # Planck's Constant
c = const.c  # Speed Of Light
k = const.k  # Boltzmann Constant

# Define Planck's Distribution Law For Black Body Radiation
def Plancks_law(lm,T):
    return 8*pi*h*c / (lm**5 * (np.exp(h*c / (lm*k*T)) - 1))

# Define Rayleigh-Jeans Function
def Rayleigh_Jeans(lm,T):
    return 8*pi*k*T/lm**4

lm = np.arange(100e-9, 30e-6, 5e-9)  # Wavelength In Meter
T = np.arange(300,3300,300)  # Temperature In Kelvin

# Planck's Distribution Law For Black Body Radiation
for i in range(len(T)):
    plt.plot(lm*1e9, Plancks_law(lm,T[i]), label=f'T = {T[i]} K')
    plt.legend(title='Temperature')
    plt.xlabel("Wavelength (nm)")
    plt.ylabel("Temperature in Kelvin")
    plt.title("Planck's Distribution Law For Black Body Radiation")
plt.show()

# Compare Planck's Distribution Law With Raleigh-Jeans Law At Low Temperature
plt.plot(lm*1e9, Plancks_law(lm,300)*1e-3, color = 'teal', label="Planck's Law (T = 300 K)")
plt.plot(lm*1e9, Rayleigh_Jeans(lm,300)*1e-3, color = 'darksalmon', label="Rayleigh-Jeans Law (T = 300 K)")
plt.ylim(0,0.005)
plt.legend()
plt.xlabel("Wavelength (nm)")
plt.ylabel("Temperature in Kelvin")
plt.title("Compare Planck's Distribution Law With Raleigh-Jeans Law At Low Temperature", fontsize=17)
plt.show()

# Compare Planck's Distribution Law With Raleigh-Jeans Law At High Temperature
plt.plot(lm*1e9, Plancks_law(lm,3000)*1e-3, color = 'teal', label="Planck's Law (T = 3000 K)")
plt.plot(lm*1e9, Rayleigh_Jeans(lm,3000)*1e-3, color = 'darksalmon', label="Rayleigh-Jeans Law (T = 3000 K)")
plt.ylim(0,140)
plt.legend()
plt.xlabel("Wavelength (nm)")
plt.ylabel("Temperature in Kelvin")
plt.title("Compare Planck's Distribution Law With Raleigh-Jeans Law At High Temperature", fontsize=17)
plt.show()
  • Total 2 snippets
  • 1