« home

Harmonic Oscillator Energy vs inverse Temperature

physicsthermodynamicscetztikz

Harmonic oscillator energy vs inverse temperature beta = 1/(kB T)


Harmonic Oscillator Energy vs inverse Temperature

  Download

PNGPDFSVG

  Code

  LaTeX

harmonic-oscillator-energy-vs-inv-temp.tex (24 lines)

\documentclass{standalone}

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

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      xlabel = $\beta$,
      ylabel = $\langle E\rangle/\hbar \omega$,
      ymin = 0,ymax = 2.3,
      domain = 0:11,
      smooth,thick,
      axis lines = center,
      every tick/.style = thick]

    \def\h{1}\def\w{1}
    \def\eev{1/2*\h*\w*(1 + 4/(e^(x*\h*\w) - 1))}
    \addplot[color=blue]{\eev};

  \end{axis}
\end{tikzpicture}
\end{document}

  Typst

harmonic-oscillator-energy-vs-inv-temp.typ (46 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)

#let size = (8, 5)

#canvas({
  draw.set-style(
    axes: (
      y: (label: (anchor: "north-west", offset: -0.2), mark: (end: "stealth", fill: black)),
      x: (label: (anchor: "north", offset: 0.1), mark: (end: "stealth", fill: black)),
    ),
  )

  plot.plot(
    size: size,
    x-min: 0,
    x-max: 11,
    y-min: 0,
    y-max: 2.3,
    x-label: $beta$,
    y-label: $angle.l E angle.r \/ planck.reduce omega$,
    x-tick-step: 2,
    y-tick-step: 0.5,
    axis-style: "left",
    {
      // Define constants from original
      let (h, w) = (1, 1)

      // Add the energy expectation value curve
      plot.add(
        style: (stroke: blue + 1.5pt),
        domain: (1e-5, 11),
        samples: 200, // More samples for smoother curve
        x => {
          // E = (1/2)hω(1 + 4/(exp(xhω) - 1))
          let hw = h * w
          let exp_term = calc.exp(x * hw)
          (1 / 2) * hw * (1 + 4 / (exp_term - 1))
        },
      )
    },
  )
})