-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmaxwell-boltzmann-distribution.typ
60 lines (55 loc) · 1.39 KB
/
maxwell-boltzmann-distribution.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#import "@preview/cetz:0.3.2": canvas, draw
#import "@preview/cetz-plot:0.1.1": plot
#set page(width: auto, height: auto, margin: 8pt)
// Constants (in SI units)
#let k_B = 1.38e-23 // Boltzmann constant
#let m_u = 1.66e-27 // unified atomic mass unit
// Maxwell-Boltzmann distribution function
#let maxwell_boltzmann(x, T) = {
(
4
* calc.pi
* calc.pow(m_u / (2 * calc.pi * k_B * T), 3 / 2)
* calc.pow(x, 2)
* calc.exp(-m_u * calc.pow(x, 2) / (2 * k_B * T))
)
}
#canvas({
draw.set-style(
axes: (
left: (
tick: (
label: (offset: .3, angle: 90deg),
),
),
),
)
plot.plot(
size: (10, 6),
x-label: [$v$ (m/s)],
y-label: $P(v)$,
y-max: 0.7e-3,
x-tick-step: 2000,
y-tick-step: 2e-4,
y-format: y => calc.round(10000 * y, digits: 2),
legend: "inner-north-east",
x-grid: true,
y-grid: true,
legend-style: (stroke: .5pt),
{
// Add grid lines
plot.add-hline(0, style: (stroke: 0.5pt))
plot.add-vline(0, style: (stroke: 0.5pt))
// Plot distributions for different temperatures
for (temp, color) in ((100, red), (300, orange), (1000, blue)) {
plot.add(
style: (stroke: color + 1.5pt),
domain: (0, 8000),
samples: 150,
x => maxwell_boltzmann(x, temp),
label: str(temp) + " K",
)
}
},
)
})