# Maxwell Boltzman distribution of speed 

\begin{equation}
f(v,T)=4\pi v^2(\frac{m}{2\pi kT})^{3/2}e^{\frac{-mv^2}{2 KT}}
\end{equation}

\begin{equation}
RMS=\sqrt{\frac{3kT}{m}}
\end{equation}

\begin{equation}
MPS=\sqrt{\frac{2kT}{m}}
\end{equation}

\begin{equation}
MS=\sqrt{\frac{8kT}{\pi m}}
\end{equation}


```python
import math  as mt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
```


```python
def maxwell(M,v, T):
    NA = 6.02e+23
    k = 1.38e-23
    m=M/NA
    a = m/(2*k)
    b =(a /(np.pi))**1.5
    prob =b*T**(-1.5) *4*np.pi*v**2*np.exp(-a*v**2/T) 
    return prob
```


```python
def maxwell1(M,v, T):
    NA = 6.02e+23
    k = 1.38e-23
    m=M/NA
    a = m/(2*k)*v**2
    b =(a /(np.pi))**1.5
    prob2 =b*T**(-1.5) *4*np.pi*v**2 
    return prob2
```


```python
def maxwell2(M,v, T):
    NA = 6.02e+23
    k = 1.38e-23
    m=M/NA
    a = m/(2*k)*v**2
    b =(a /(np.pi))**1.5
    prob3 =np.exp(-a*v**2/T)
    return prob3
```


```python
Mo=16e-3 #mass of oxygen
Mh=2e-3 # mass of hydrogen
Mn=28e-3 # mass of nitrogen
velocity = np.arange(100, 750, 10) 
```


```python
# probability  for oxygen at 200K,300K,400K
prob200 = maxwell(Mo,velocity, 100.0)
prob300 = maxwell(Mo,velocity, 200.0)
prob400 = maxwell(Mo,velocity, 300.0)
```


```python
# probability  for oxygen at 200K,300K,400K
prob2001 = maxwell1(Mo,velocity, 100.0)
prob3001 = maxwell1(Mo,velocity, 200.0)
prob4001 = maxwell1(Mo,velocity, 300.0)
```


```python
# probability  for oxygen at 200K,300K,400K
prob2002 = maxwell2(Mo,velocity, 100.0)
prob3002 = maxwell2(Mo,velocity, 200.0)
prob4002 = maxwell2(Mo,velocity, 300.0)
```


```python
plt.plot(velocity, prob200, 'g-',label='100k') 
plt.plot(velocity, prob300, 'b-',label='200k') 
plt.plot(velocity, prob400, 'r-',label='300k') 
plt.xlabel('Velocity(m/s)')
plt.ylabel('Probability')
plt.title('Maxwell Boltzman distribution of speed for Oxygen')         
plt.legend()
plt.savefig("image/BoltmanO.png", dpi = 600) # dpi dot per inch
plt.show()
```


```python
plt.plot(velocity, prob2001, 'g-',label='100k') 
plt.plot(velocity, prob3001, 'b-',label='200k') 
plt.plot(velocity, prob4001, 'r-',label='300k') 
plt.xlabel('Velocity(m/s)')
plt.ylabel('Probability')
plt.title('Maxwell Boltzman distribution of speed for Oxygen')         
plt.legend()
plt.savefig("image/Boltman1.png", dpi = 600) # dpi dot per inch
plt.show()
```


```python
plt.plot(velocity, prob2002, 'g-',label='100k') 
plt.plot(velocity, prob3002, 'b-',label='200k') 
plt.plot(velocity, prob4002, 'r-',label='300k') 
plt.xlabel('Velocity(m/s)')
plt.ylabel('Probability')
plt.title('Maxwell Boltzman distribution of speed for Oxygen')         
plt.legend()
plt.savefig("image/Boltman2.png", dpi = 600) # dpi dot per inch
plt.show()
```


```python
plt.semilogy(velocity, prob300, 'g-',label='original') 
plt.semilogy(velocity, prob3001, 'b-',label='v2') 
plt.semilogy(velocity, prob3002, 'r-',label='exp') 
plt.xlabel('Velocity(m/s)')
plt.ylabel('Probability')
plt.title('Maxwell Boltzman distribution of speed for Oxygen')         
plt.legend()
plt.savefig("image/Boltman3.png", dpi = 600) # dpi dot per inch
plt.show()
```


```python
M = {"Velocity(m/s)": velocity,"Probability(100K)": prob200,"Probability(200K)": prob300,"Probability(300K)": prob400}
```


```python
DF = pd.DataFrame(M)
DF
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Velocity(m/s)</th>
      <th>Probability(100K)</th>
      <th>Probability(200K)</th>
      <th>Probability(300K)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>0.000612</td>
      <td>0.000227</td>
      <td>0.000126</td>
    </tr>
    <tr>
      <th>1</th>
      <td>110</td>
      <td>0.000726</td>
      <td>0.000272</td>
      <td>0.000151</td>
    </tr>
    <tr>
      <th>2</th>
      <td>120</td>
      <td>0.000845</td>
      <td>0.000320</td>
      <td>0.000178</td>
    </tr>
    <tr>
      <th>3</th>
      <td>130</td>
      <td>0.000969</td>
      <td>0.000371</td>
      <td>0.000208</td>
    </tr>
    <tr>
      <th>4</th>
      <td>140</td>
      <td>0.001094</td>
      <td>0.000425</td>
      <td>0.000239</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>60</th>
      <td>700</td>
      <td>0.000295</td>
      <td>0.001104</td>
      <td>0.001319</td>
    </tr>
    <tr>
      <th>61</th>
      <td>710</td>
      <td>0.000265</td>
      <td>0.001061</td>
      <td>0.001297</td>
    </tr>
    <tr>
      <th>62</th>
      <td>720</td>
      <td>0.000237</td>
      <td>0.001019</td>
      <td>0.001274</td>
    </tr>
    <tr>
      <th>63</th>
      <td>730</td>
      <td>0.000212</td>
      <td>0.000977</td>
      <td>0.001250</td>
    </tr>
    <tr>
      <th>64</th>
      <td>740</td>
      <td>0.000189</td>
      <td>0.000935</td>
      <td>0.001225</td>
    </tr>
  </tbody>
</table>
<p>65 rows × 4 columns</p>
</div>




```python
DF.to_csv("data/Boltzman.csv")
```


```python
# probability  for hydrogen,nitrogen ,oxygen at 300K
probh = maxwell(Mh,velocity, 300) # for hydrogen
probn = maxwell(Mn,velocity, 300) # for nitrogen
probo = maxwell(Mo,velocity, 300) #for oxygen
```


```python
plt.plot(velocity, probh, 'g-',label='Hydrogen') 
plt.plot(velocity, probn, 'b-',label='Nitrogen') 
plt.plot(velocity, probo, 'r-',label='Oxygen') 
plt.xlabel('Velocity(m/s)')
plt.ylabel('Probability')
plt.title('Maxwell Boltzman distribution of speed for gas at ')         
plt.legend()
plt.savefig("image/Boltmanal.png", dpi = 600) # dpi dot per inch
plt.show()
```


```python
def rms(M,T):
    NA = 6.02e+23
    k = 1.38e-23
    m=M/NA
    vel =np.sqrt(3*k*T/m) 
    return vel
```


```python
temp = np.arange(200, 500, 10) 
```


```python
# rms for gas 
rmsh = rms(Mh,temp) #for hydrogen
rmso = rms(Mo,temp) #for oxygen
rmsn = rms(Mn,temp) #for nitrogen
```


```python
plt.plot(temp, rmsh, 'g-',label='Hydrogen') 
plt.plot(temp, rmso, 'b-',label='Oxygen') 
plt.plot(temp, rmsn, 'r-',label='Nitrogen') 
plt.xlabel('Temperature(K)')
plt.ylabel('RMS(m/s)')
plt.title('RMS speed for gas')         
plt.legend()
plt.savefig("image/rms.png", dpi = 600) # dpi dot per inch
plt.show()
```

# Planck's formula of radiation

\begin{equation}
f(\lambda,T)=\frac{2hc^2}{\lambda^5}\frac{1}{e^{\frac{hc}{\lambda KT}}-1}
\end{equation}


```python
def planck(wav, T):
    h = 6.626e-34
    c = 3.0e+8
    k = 1.38e-23
    a = 2.0*h*c**2
    b = h*c/(wav*k*T)
    intensity = a/ ( (wav**5) * (np.exp(b) - 1.0) )
    return intensity
```


```python
wavelengths = np.arange(6e-9, 2e-6, 1e-9) # wavelength in m
```


```python
# intensity at 4000K, 5000K, 6000K, 7000K
intensity4000 = planck(wavelengths, 4000)
intensity5000 = planck(wavelengths, 5000)
intensity6000 = planck(wavelengths, 6000)
intensity7000 = planck(wavelengths, 7000)
```


```python
plt.plot(wavelengths*1e9, intensity4000, 'r-',label='4000k') 
plt.plot(wavelengths*1e9, intensity5000, 'g-',label='5000k') 
plt.plot(wavelengths*1e9, intensity6000, 'k-',label='6000k') 
plt.xlabel('Wavelength(nm)')
plt.ylabel('Spetral energy densiry(W/m$^3$)')
plt.title('Black body radiation')         
plt.legend()
plt.savefig("image/planck.png", dpi = 600) # dpi dot per inch
plt.show()
```


```python
M1 = {"wavelength(m)": wavelengths,"Intensity(4000K)": intensity4000,"Intensity(5000K)": intensity5000,"Intensity(6000K)": intensity6000}
```


```python
DF1 = pd.DataFrame(M1)
DF1
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>wavelength(m)</th>
      <th>Intensity(4000K)</th>
      <th>Intensity(5000K)</th>
      <th>Intensity(6000K)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>6.000000e-09</td>
      <td>3.391580e-236</td>
      <td>4.586434e-184</td>
      <td>2.603298e-149</td>
    </tr>
    <tr>
      <th>1</th>
      <td>7.000000e-09</td>
      <td>2.704885e-199</td>
      <td>1.305948e-154</td>
      <td>8.037306e-125</td>
    </tr>
    <tr>
      <th>2</th>
      <td>8.000000e-09</td>
      <td>1.173680e-171</td>
      <td>1.471820e-132</td>
      <td>1.711556e-106</td>
    </tr>
    <tr>
      <th>3</th>
      <td>9.000000e-09</td>
      <td>3.428211e-150</td>
      <td>1.945881e-115</td>
      <td>2.873970e-92</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1.000000e-08</td>
      <td>4.822859e-133</td>
      <td>9.161117e-102</td>
      <td>6.521953e-81</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>1989</th>
      <td>1.995000e-06</td>
      <td>7.428806e+11</td>
      <td>1.165626e+12</td>
      <td>1.618849e+12</td>
    </tr>
    <tr>
      <th>1990</th>
      <td>1.996000e-06</td>
      <td>7.418241e+11</td>
      <td>1.163810e+12</td>
      <td>1.616189e+12</td>
    </tr>
    <tr>
      <th>1991</th>
      <td>1.997000e-06</td>
      <td>7.407693e+11</td>
      <td>1.161998e+12</td>
      <td>1.613535e+12</td>
    </tr>
    <tr>
      <th>1992</th>
      <td>1.998000e-06</td>
      <td>7.397163e+11</td>
      <td>1.160190e+12</td>
      <td>1.610887e+12</td>
    </tr>
    <tr>
      <th>1993</th>
      <td>1.999000e-06</td>
      <td>7.386651e+11</td>
      <td>1.158385e+12</td>
      <td>1.608244e+12</td>
    </tr>
  </tbody>
</table>
<p>1994 rows × 4 columns</p>
</div>




```python
DF1.to_csv("data/planck.csv")
```

777f04d10abbdab7cb52aaf5803297a96e5cfbeb
ipynb
Jupyter Notebook
maxwell.ipynb
joshidot/NPS
0b5b7dde9b5a9769c8a437d193b210545f9344ca
MIT
maxwell.ipynb
joshidot/NPS
0b5b7dde9b5a9769c8a437d193b210545f9344ca
MIT
maxwell.ipynb
joshidot/NPS
0b5b7dde9b5a9769c8a437d193b210545f9344ca
MIT
Qwen/Qwen-72B
1. YES
2. YES