Possible Duplicate:
Is plotting exponential graphs a known source of bugs in TikZ?
I want to use a custom function in pgf plots and in text, like in this example:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\def\frho(#1){pow(#1,(1/\fKappa))}%
% \pgfmathdeclarefunction{rho}{1}{%
% \pgfmathparse{pow(#1,(1/\fKappa))}%
% }
\begin{document}
\pgfmathsetmacro{\fKappa}{1.4}
\pgfmathparse{\frho(0.15)}$\rho(0.15) = \pgfmathresult$\\
\begin{tikzpicture}
\begin{axis}[name=upper,
xmin=0,xmax=1,width=10cm,
ymin=0,ymax=1,height=10cm,
scale only axis,
x dir=reverse,
xlabel={$p$},
ylabel={$\rho$}
]
\addplot[domain=0.001:1,samples=50,smooth] {\frho(x)};
\end{axis}
\end{tikzpicture}
\end{document}
The outcoming plot is correct, but the text result is not: the pdf says rho(0.15) = 3.84593. This happens with the \def variant as well as with the \pgfmathdeclarefunction variant. I don't think this might be caused by the limitations of pow, because one result is correct.
How can I fix this?
expfunction ofpgfmath, which is used internally by thepowfunction. It's been fixed in the CVS version ofpgf. If you don't want to update to the CVS version, you can just copy the relevant bit of code into your document: http://tex.stackexchange.com/a/31791/2552. The function works in pgfplots because it uses thefpuengine, which reimplements theexpfunction correctly. – Jake Feb 02 '12 at 12:08