[Tex/LaTex] Package PGF Math Error: Sorry, an internal routine of the floating point unit

errorsloopsparameterspgfmath

This type of error (! Package PGF Math Error: Sorry, an internal routine of the floating point unit got an ill-formatted floating point number …) arises when trying to use a predefined list for the \pgfplotsforeachungrouped-loop. This problem is related to parameter studies where all significant parameters are put into a list, e.g. Create Table for a Family of Curves.

Following MWE shows the compiling error:

\documentclass[border=1mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\pgfplotstableread{
1
2
3
4
5
}\dataQuad

\newcommand{\param}{2,3,4,5}

\pgfplotsforeachungrouped \y in \param {%
    \pgfplotstablecreatecol[
        create col/expr={\thisrow{0}^\y}
    ]{\y}\dataQuad
}

\begin{document}
    \begin{minipage}[c]{0.75\textwidth}
        \begin{tikzpicture}
            \begin{axis}[%
                legend pos=north west,
                domain=0:5,
                cycle list={green, red, black, purple, orange},
                xlabel=${x}$,
                ylabel=${y}$]
            \pgfplotsinvokeforeach{2,...,5}{
                    \addplot +[smooth] table [x index=0, y=#1] \dataQuad;
            }
            \end{axis}
        \end{tikzpicture}
    \end{minipage}

    \begin{minipage}[c]{0.75\textwidth}
        \pgfplotstabletypeset\dataQuad
    \end{minipage}
\end{document}

A similar problem was discussed here Using Macro Defined Lists in TikZ/PGFplots, but don't bring any solution for this particular problem.

So far I use \newcommand{\paramA}{2},\newcommand{\paramB}{3}, and so forth and looping via \pgfplotsforeachungrouped \y in {\paramA,...,\paramE} {%. The main drawback with this is when I need to change the number of parameters.

May someone have a more elegant way for using a predefined parameter list that can be used for every loop type like \foreach, \pgfplotsforeachungrouped and \pgfplotsinvokeforeach. Any hint is much appreciated!

Best Answer

You can use \pgfplotsinvokeforeach with a bit of \expandafter-trickery:

\documentclass[border=1mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\pgfplotstableread{
1
2
3
4
5
}\dataQuad

\newcommand{\param}{2,3,4,5}

\expandafter\pgfplotsinvokeforeach\expandafter{\param}{%
    \pgfplotstablecreatecol[
        create col/expr={\thisrow{0}^#1}
    ]{#1}\dataQuad
}

\begin{document}
    \begin{minipage}[c]{0.75\textwidth}
        \begin{tikzpicture}
            \begin{axis}[%
                legend pos=north west,
                domain=0:5,
                cycle list={green, red, black, purple, orange},
                xlabel=${x}$,
                ylabel=${y}$]
            \pgfplotsinvokeforeach{2,...,5}{
                    \addplot +[smooth] table [x index=0, y=#1] \dataQuad;
            }
            \end{axis}
        \end{tikzpicture}
    \end{minipage}

    \begin{minipage}[c]{0.75\textwidth}
        \pgfplotstabletypeset\dataQuad
    \end{minipage}
\end{document}
Related Question