« home

Maxwell Boltzmann Distribution

physicsstatistical mechanicsthermodynamicscetztikz

The Maxwell-Boltzmann distribution plotted at different temperatures reveals that the most probable velocity vpv_p of ideal gas particles scales with the square root of temperature.


Maxwell Boltzmann Distribution

  Download

PNGPDFSVG

  Code

  LaTeX

maxwell-boltzmann-distribution.tex (36 lines)

\documentclass{standalone}

\usepackage{pgfplots,siunitx}
\pgfplotsset{compat=newest}

\def\kB{1.38e-23} % Boltzmann constant
\def\mu{1.66e-27} % unified atomic mass unit/Dalton (symbols: m_u or Da)

\def\maxwellboltzmann#1{4 * pi * (\mu / (2 * pi * \kB * #1))^(3/2) * x^2 * exp(-\mu * x^2 / (2 * \kB * #1))}

\begin{document}

\begin{tikzpicture}

  \begin{axis}[
      domain = 0:8000,
      xlabel = {$v$ [\si{\metre\per\second}]},
      ylabel = $P(v)$,
      smooth, thick,
      axis lines = left,
      every tick/.style = {thick},
    ]

    \addplot[color=red,samples=100]{\maxwellboltzmann{100}};

    \addplot[color=yellow]{\maxwellboltzmann{300}};

    \addplot[color=blue]{\maxwellboltzmann{1000}};

    \legend{\SI{100}{\kelvin}, \SI{300}{\kelvin}, \SI{1000}{\kelvin}}

  \end{axis}
\end{tikzpicture}

\end{document}

  Typst

maxwell-boltzmann-distribution.typ (61 lines)

#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",
        )
      }
    },
  )
})