# \pgfmathsetmacro creates “Dimensions too large” for t distribution

I am trying to plot 't' distribution with area of interest shaded. I have done both plotting and sharing area. Next tried to draw vertical lines closing the shaded area on both sides. For this, I need to calculate the point on the curve for upper end point of the line to be drawn.

For this, I tried to use \pgfmathsetmacro which is throwing dimensions too large error. I use texstudio and tried \tracingmacros2 but unable to find the problem. I wonder why this error, because the code is able to draw the related curve using same function successfully, so why too large number returned for specific point (which is in the range of the x axis of curve drawn). Kindly help.

MWE:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
%\tracingmacros2
%\tracingassigns2

\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{student}{2}{%
\pgfmathparse{gamma((#2+1)/2.)/(sqrt(#2*pi) *gamma(#2/2.)) *((1+(#1*#1)/#2)^(-(#2+1)/2.))}%
}

\begin{tikzpicture}

\begin{axis}[
axis lines=left,
enlargelimits=upper,
samples=100
]

\def\df{3}
\def\cilow{-3.182}
\def\cihigh{3.182}
\addplot [draw=none, fill=yellow!25, domain=\cilow:\cihigh] {student(x, \df)} \closedcycle;

%\pgfmathsetmacro\valueA{student(1, 3)}
%\draw [gray] (axis cs:\cilow,0) -- (axis cs:\cilow,\valueA);

\end{axis}
\end{tikzpicture}
\end{document}


Output (with problematic line commented):

Online editor for easy reproduction and analysis: Here

Not really sure what happens, but if you use the student function in the coordinate directly, it works fine. I.e.

\draw [gray] (axis cs:\cilow,0) -- (axis cs:\cilow,{student(\cilow, \df)});


Alternatively use a ycomb plot to make those two vertical lines:

\addplot [ycomb, gray, no markers, samples at={\cilow, \cihigh}] {student(x, \df)};


Complete code:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
%\tracingmacros2
%\tracingassigns2

\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{student}{2}{%
\pgfmathparse{gamma((#2+1)/2.)/(sqrt(#2*pi) *gamma(#2/2.)) *((1+(#1*#1)/#2)^(-(#2+1)/2.))}%
}

\begin{tikzpicture}

\begin{axis}[
axis lines=left,
enlargelimits=upper,
samples=100
]

\def\df{3}
\def\cilow{-3.182}
\def\cihigh{3.182}
\addplot [draw=none, fill=yellow!25, domain=\cilow:\cihigh] {student(x, \df)} \closedcycle;

• I guess that the error appears since you are using an ordinary \draw command, which does, unlike \addplot, not use fpu. (Of course, one might make it use that.) – user121799 Sep 29 '18 at 12:26