Skip to content

Commit 3070466

Browse files
Add files via upload
1 parent d7a23e7 commit 3070466

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

MB-interactive.ipynb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "c48badf8-e0a6-4d31-a3be-8391267f0c51",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"data": {
11+
"application/vnd.jupyter.widget-view+json": {
12+
"model_id": "de4b4fa1f17446bbb1b4a5e4dcb1f408",
13+
"version_major": 2,
14+
"version_minor": 0
15+
},
16+
"text/plain": [
17+
"interactive(children=(IntSlider(value=300, description='T', max=1000, min=100, step=50), Output()), _dom_class…"
18+
]
19+
},
20+
"metadata": {},
21+
"output_type": "display_data"
22+
},
23+
{
24+
"data": {
25+
"text/plain": [
26+
"<function __main__.plot_MB(T=300)>"
27+
]
28+
},
29+
"execution_count": 1,
30+
"metadata": {},
31+
"output_type": "execute_result"
32+
}
33+
],
34+
"source": [
35+
"import numpy as np\n",
36+
"import matplotlib.pyplot as plt\n",
37+
"from ipywidgets import interact\n",
38+
"\n",
39+
"# Boltzman constant, J.K-1, atomis mass unit (kg)\n",
40+
"kB, u = 1.381e-23, 1.661e-27\n",
41+
"\n",
42+
"# Gas particle masses, in kg\n",
43+
"m_He, m_Ar = 4 * u, 40 * u\n",
44+
"\n",
45+
"# Temperature in K\n",
46+
"T = 300\n",
47+
"\n",
48+
"# The value of the Maxwell-Boltzmann distribution\n",
49+
"def fMB(v, T, m): # mass in kg, at temperature in K, at the speed v (in m.s-1)\n",
50+
" fac = m /2 /kB/T\n",
51+
" return (fac / np.pi)**1/5 * 4 * np.pi * v**2 * np.exp(-fac * v **2)\n",
52+
"\n",
53+
"def plot_MB(T=300):\n",
54+
" v= np.linspace(0, 3000, 3000)\n",
55+
" fv_He = fMB(v, T, m_He)\n",
56+
" fv_Ar = fMB(v, T, m_Ar)\n",
57+
"\n",
58+
"# Plot He and Ar distribution\n",
59+
" plt.plot(figsize=(8,6))\n",
60+
" plt.plot(v, fv_He, color='orange', label=f'He, T{T}K')\n",
61+
" plt.plot(v, fv_Ar, color='blue', ls='--', label=f'Ar, T{T}K')\n",
62+
" \n",
63+
" plt.xlabel('Speed v /m.s-1', fontsize=14)\n",
64+
" plt.ylabel('Density f(v) /s.m-1', fontsize=14)\n",
65+
" plt.legend()\n",
66+
" plt.legend(framealpha=0.7, fontsize=14, loc='upper right', bbox_to_anchor=(0.98, 1))\n",
67+
" plt.grid(True, color='gray', zorder=0, linestyle='--')\n",
68+
" plt.show()\n",
69+
"\n",
70+
"interact(plot_MB, T=(100, 1000, 50))"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"id": "893b6a24-775b-48ec-ac44-66d188be717f",
77+
"metadata": {},
78+
"outputs": [],
79+
"source": []
80+
}
81+
],
82+
"metadata": {
83+
"kernelspec": {
84+
"display_name": "myenv",
85+
"language": "python",
86+
"name": "myenv"
87+
},
88+
"language_info": {
89+
"codemirror_mode": {
90+
"name": "ipython",
91+
"version": 3
92+
},
93+
"file_extension": ".py",
94+
"mimetype": "text/x-python",
95+
"name": "python",
96+
"nbconvert_exporter": "python",
97+
"pygments_lexer": "ipython3",
98+
"version": "3.13.9"
99+
}
100+
},
101+
"nbformat": 4,
102+
"nbformat_minor": 5
103+
}

0 commit comments

Comments
 (0)