我想绘制这条曲线:
使用 tikz,我做了以下事情
\begin{tikzpicture}
\draw [<->,thick] (0,5) node (yaxis) [above, text width=3.5cm,align=center] {$B_{J}(x)$}
|- (7,0) node (xaxis) [right] {$x$};
\draw (0,0)--(0.3,0.9)--(0.6,1.2);
\end{tikzpicture}
但是,坐标让我头疼。有没有简单的方法可以做到这一点?
答案1
假设我得到的方程式正确,那么您可以尝试使用LuaLaTeX
:
\documentclass[border=5]{standalone}
\usepackage{tikz}
\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]
\draw [help lines] (-5,0) -- (10,0);
\draw [help lines, -stealth] (0,-1) -- (0,1.5);
\draw [densely dotted] (0,{ Brillouin(1, 100)} ) -- ++(10,0);
\draw [red] plot [domain=-5:10, samples=100] (\x, { Brillouin(1, \x)});
\draw [green] plot [domain=-5:10, samples=100] (\x, { Brillouin(5, \x)});
\draw [blue] plot [domain=-5:10, samples=100] (\x, { Brillouin(50, \x)});
\end{tikzpicture}
\end{document}
答案2
\draw plot
就像这样。在 tikz 中使用命令。
更新根据 OP 关于与原始图不匹配的评论,此更新提供了具有time constant
能力的一阶指数图。(可以将 y 标签 2 更改为 1。)更改\a
具有相应时间常数的不同图的参数值。
代码
\documentclass[border=10pt]{standalone}%{article}
\usepackage{tikz}
\pagestyle{empty}
\def\a{3} % time constant=1/a
\begin{document}
\begin{tikzpicture}
\draw [<->,thick] (0,2.5) node (yaxis) [above, text width=3.5cm,align=center] {$B_{J}(x)$} |- (5,0) node (xaxis) [right] {$x$};
\draw[dashed] (0,2)node[left]{2}--node[above]{value}(3,2);
\node[left] at (0,0){0};
\draw[red] plot[domain=0:4,samples=50] ({\x},{2-2*exp(-\a*\x)}); % <-- \a is added
\end{tikzpicture}
\end{document}
代码
\documentclass[border=10pt]{standalone}%{article}
\usepackage{tikz}
%\usepackage{pgfplots,pgfplotstable}
%\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\draw [<->,thick] (0,3) node (yaxis) [above, text width=3.5cm,align=center] {$B_{J}(x)$} |- (7,0) node (xaxis) [right] {$x$};
\draw[dashed] (0,1)node[left]{1}--node[above]{above}(5,1);
\node[left] at (0,0){0};
\draw[red] plot[domain=0:5] ({\x},{1-exp(-\x)});
\end{tikzpicture}
\end{document}
答案3
这是一个使用选项pgfplots
,它基于tikz
,但简化了此类函数的绘制。
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[tikz,border=2pt]{standalone}
\usepackage{pgfplots}
% arrows are stealth fighters
\tikzset{>=stealth}
\begin{document}
\begin{tikzpicture}[
/pgf/declare function={coth(\x)=1/tanh(\x);},
/pgf/declare function={brillouin(\x,\J)=%
(2*\J+1)*coth( (2*\J+1)*\x/(2*\J) )/(2*\J)-coth(\x/(2*\J))/(2*\J);
},
]
\begin{axis}[
axis x line=middle,
axis y line=middle,
axis line style=->,
ymax=2,
grid=none,
samples=100,
xtick={-1},
ytick={1},
xlabel={$x$},
ylabel={$B_J(x)$},
]
\addplot+[domain=0.1:5,no marks,thick] {brillouin(x,1)};
\addplot+[domain=0.1:5,no marks,ultra thick] {brillouin(x,2)};
\addplot [domain=0:5,dashed]{1}node[pos=0.5,anchor=south]{value};
\end{axis}
\end{tikzpicture}
\end{document}
答案4
仅用于使用 PSTricks 进行打字练习。
\documentclass[pstricks,border=15pt,12pt,dvipsnames]{standalone}
\usepackage{pst-math,pst-plot}
\def\f#1{(2*#1+1)/(2*#1*TANH((2*#1+1)/(2*#1)*x))-1/(2*#1*TANH(x/(2*#1)))}
\psset
{
xAxisLabel=$x$,
yAxisLabel=$y$,
algebraic,
}
\begin{document}
\begin{psgraph}[linecolor=gray,tickcolor=gray]{<->}(0,0)(-6.5,-1.5)(6.5,1.5){12cm}{8cm}
\foreach \n/\c in {2/Red,3/ForestGreen,5/NavyBlue,7/Maroon}{%
\psplot[linecolor=\c]{-6}{6}{\f{\n}}}
\end{psgraph}
\end{document}