
Normal 및 Student T 분포에 대한 다양한 그림을 그리고 있습니다. 아래에는 두 분포를 모두 보여주는 간단한 그림의 MWE가 나와 있습니다. 직접 Student T 연산을 이용하여 수직선을 그어보니 괜찮습니다. 동일한 계산을 pgfmathsetmacro에 넣었는데 "! 차원이 너무 큽니다."라는 메시지가 표시되지 않습니다.
실제 응용 프로그램에서는 rgtCH 값이 여러 곳에서 사용됩니다. 계산하는 데 TeX 시간이 좀 걸리기 때문에 매번 다시 계산하기보다는 한 번 계산하고 그 결과를 변수에 넣어 재사용할 수 있도록 하려고 했습니다. 실제 애플리케이션에서는 이 모든 것이 매개변수화되어 있습니다. MWE를 최대한 단순하게 만들기 위해 매개변수화를 최대한 제거했습니다. 나는 분명히 pgf의 초보자이므로 누군가 내가 뭘 잘못하고 있는지 이해하도록 도와줄 수 있다면 감사하겠습니다.
\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{DistAxis/.style={%
no markers,
domain=-4:4, % Only display z values between -4 and 4.
samples=100,
xlabel=\textbf{t},
every axis x label/.style={at={(axis description cs:1.0, 0.0)}, anchor=west},
height=5cm, width=12cm,
xtick=\empty, ytick=\empty,
enlargelimits=false,
clip=false,
axis on top=true,
hide y axis,
axis x line*=middle,
axis line style ={thick,latex-latex}}
}
\pgfmathdeclarefunction{std_norm}{1}{%
\pgfmathparse{1/(sqrt(2*pi))*exp(-((#1)^2)/(2))}%
}
\pgfmathdeclarefunction{gamma}{1}{%
\pgfmathparse{2.506628274631*sqrt(1/#1) + 0.20888568*(1/#1)^(1.5) + %
0.00870357*(1/#1)^(2.5) - (174.2106599*(1/#1)^(3.5))/25920 - %
(715.6423511*(1/#1)^(4.5))/1244160)*exp((-ln(1/#1)-1)*#1}%
}
\pgfmathdeclarefunction{std_stud}{2}{%
\pgfmathparse{gamma(.5*(#1+1))/(sqrt(#1*pi)*gamma(.5*#1))*((1+(#2*#2)/#1)^(-.5*(#1+1)))}%
}
\begin{document}
\begin{tikzpicture}[scale=0.6]
\begin{axis}[DistAxis]
% If you comment the first and uncomment the second, this fails to compile. Why?
\pgfmathsetmacro{\rgtCH}{ 0.075+std_norm(1.0))};
% \pgfmathsetmacro{\rgtCH}{ 0.075+std_stud(9, 1.0))};
\draw [thick,magenta,dashed] (axis cs:1.0, -0.02) -- (axis cs:1.0, {0.075+std_stud(9,1.0)});
\draw [thick,magenta,dashed] (axis cs:1.0, -0.02) -- (axis cs:1.0, {\rgtCH});
\addplot [very thick,blue] {std_norm(x)};
\addplot [very thick,red] {std_stud(9,x)};
\end{axis}
\end{tikzpicture}
\end{document}
다음은 정규 분포와 스튜던트 T 분포 계산이 모두 작동하고 있음을 보여주는 이미지입니다.
답변1
기본적으로 in은 \pgfmathsetmacro
fpu
꺼져 있습니다. 스위치를 켜면 dimension too large
오류가 사라집니다.
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\pgfplotsset{DistAxis/.style={%
no markers,
domain=-4:4, % Only display z values between -4 and 4.
samples=100,
xlabel=\textbf{t},
every axis x label/.style={at={(axis description cs:1.0, 0.0)}, anchor=west},
height=5cm, width=12cm,
xtick=\empty, ytick=\empty,
enlargelimits=false,
clip=false,
axis on top=true,
hide y axis,
axis x line*=middle,
axis line style ={thick,latex-latex}}
}
\newcommand{\pgfmathparseFPU}[1]{\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathparse{#1}%
\pgfmathsmuggle\pgfmathresult\endgroup}
\pgfmathdeclarefunction{std_norm}{1}{%
\pgfmathparseFPU{1/(sqrt(2*pi))*exp(-((#1)^2)/(2))}%
}
\pgfmathdeclarefunction{gamma}{1}{%
\pgfmathparseFPU{2.506628274631*sqrt(1/#1) + 0.20888568*(1/#1)^(1.5) + %
0.00870357*(1/#1)^(2.5) - (174.2106599*(1/#1)^(3.5))/25920 - %
(715.6423511*(1/#1)^(4.5))/1244160)*exp((-ln(1/#1)-1)*#1}%
}
\pgfmathdeclarefunction{std_stud}{2}{%
\pgfmathparseFPU{gamma(.5*(#1+1))/(sqrt(#1*pi)*gamma(.5*#1))*((1+(#2*#2)/#1)^(-.5*(#1+1)))}%
}
\begin{document}
\begin{tikzpicture}[scale=0.6]
\begin{axis}[DistAxis]
% If you comment the first and uncomment the second, this fails to compile. Why?
\pgfmathsetmacro{\rgtCH}{ 0.075+std_norm(1.0))};
\pgfmathsetmacro{\rgtCH}{ 0.075+std_stud(9, 1.0))};
\draw [thick,magenta,dashed] (axis cs:1.0, -0.02) -- (axis cs:1.0, {0.075+std_stud(9,1.0)});
\draw [thick,magenta,dashed] (axis cs:1.0, -0.02) -- (axis cs:1.0, {\rgtCH});
\addplot [very thick,blue] {std_norm(x)};
\addplot [very thick,red] {std_stud(9,x)};
\end{axis}
\end{tikzpicture}
\end{document}