Created
June 27, 2016 12:06
-
-
Save windstriver/80c4c6ee75ac8b413b30d9f5b347800e to your computer and use it in GitHub Desktop.
Example: Plot of the Brillouin Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment