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]  •  [Open in Overleaf]

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
function coth (i) 
  return math.cosh(i) / math.sinh(i)

function brillouin (J, x) 
  if x == 0 then
    return 0
   return (2*J+1)/(2*J)*coth((2*J+1)/(2*J)*x) - 
     \directlua{tex.print("" .. brillouin(#1,#2))}%
    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) {%
      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 )


Adding comments is currently not enabled.

Scientific and technical areas


LaTeX Beginners Guide

Limited discount 50%
coupon code tDRet6Y

Creative Commons License