¿Pgfmathsetmacro falla en el cálculo de T del estudiante?

¿Pgfmathsetmacro falla en el cálculo de T del estudiante?

Estoy dibujando varios dibujos para distribuciones Normal y T de Student. A continuación se muestra un MWE para una imagen simple que muestra ambas distribuciones. Dibujo una línea vertical usando el cálculo T de Student directamente y todo está bien. Puse el mismo cálculo en una pgfmathsetmacro y falla diciendo "¡! Dimensión demasiado grande".

En mi aplicación real, el valor de rgtCH se utiliza en varios lugares. El cálculo lleva un tiempo a TeX, por lo que estaba tratando de hacer que hiciera el cálculo una vez y colocar el resultado en una variable para reutilizarlo en lugar de volver a calcularlo cada vez. En mi aplicación real, todo esto está muy parametrizado. Para intentar que MWE sea lo más simple posible, he eliminado la mayor cantidad de parametrización posible. Es cierto que soy un novato en pgf, por lo que si alguien pudiera ayudarme a comprender qué estoy haciendo mal, se lo agradecería.

\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}

Aquí está la imagen que muestra que los cálculos de la Distribución Normal y la Distribución T de Student están funcionando.

ingrese la descripción de la imagen aquí

Respuesta1

De forma predeterminada, \pgfmathsetmacro fpuestá desactivado. Si lo enciendes, los dimension too largeerrores desaparecen.

\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}

ingrese la descripción de la imagen aquí

información relacionada