Example: Plot of the Brillouin Function

Published 2014-07-29 | Author: Mark Wibrow

The Brillouin function is a special function, used for example in statistical mechanics.

For plotting we use standard TikZ, pgfplots is not required. The calculation is done using Lua, so LuaLaTeX has to be used for compiling.

This example was written by Mark Wibrow answering a question on TeX.SE, with modifications by Stefan Kottwitz (formula, scaling, styles for axis and plot).

Download as: [PDF] [TEX]

Plot of the Brillouin Function

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% Brillouin Function
% Author: Mark Wibrow
\documentclass[tikz,border=10pt]{standalone}
\usepackage{amsmath}
\usetikzlibrary{arrows.meta}
\directlua{
function coth (i) 
  return math.cosh(i) / math.sinh(i)
end

function brillouin (J, x) 
  if x == 0 then
    return 0
  else
   return (2*J+1)/(2*J)*coth((2*J+1)/(2*J)*x) - 
        1/(2*J)*coth(1/(2*J)*x)
  end
end
}
\pgfmathdeclarefunction{Brillouin}{2}{%
  \edef\pgfmathresult{%
     \directlua{tex.print("" .. brillouin(#1,#2))}%
   }%  
}
\begin{document}
\begin{tikzpicture}[
    x                = 2cm/10,
    scale            = 3,
    axis/.style      = {help lines, -{Stealth[length = 1.5ex]}},
    brillouin/.style = {domain = -5:10, samples = 100}
  ]
  \draw [axis] (-5,0) -- (10,0);
  \draw [axis] (0,-1) -- (0,1.5);
  \draw [densely dotted] (0,{ Brillouin(1, 100)} ) -- ++(10,0);
  \draw [red]   plot [brillouin] (\x, { Brillouin(1,  \x)});
  \draw [green] plot [brillouin] (\x, { Brillouin(5,  \x)});
  \draw [blue]  plot [brillouin] (\x, { Brillouin(50, \x)});
  \node [align = center, anchor = west] at (1,1.3) {%
    $\begin{alignedat}{2}
      B_J(x) &= \tfrac{2J + 1}{2J}
                &&\coth \left ( \tfrac{2J + 1}{2J} x \right ) \\
             &\quad - \tfrac{1}{2J}
                &&\coth \left ( \tfrac{1}{2J} x \right )
     \end{alignedat}$};
\end{tikzpicture}
\end{document}

Comments

Adding comments is currently not enabled.