latexpgf

Plotting Exponentials Inside Logs in Latex pgfplots


I'm trying to add some plots to my document. I've been able to do so successfully before; but for some reason it's not working this time. I tried deleting everything except just one plot but I still get the same error. Let me just show the document with just the one plot.

\documentclass[11pt]{amsart}

\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[domain=0:3,samples=100,yticklabels=\empty]
\addplot+[no markers] {20-500*\ln(0.998*exp(-x)+0.002+0*exp(x))-500*\ln(0.998*exp(x)+0.002+0*exp(-x))};
\end{axis}
\end{tikzpicture}
\end{document}

I get the error "Undefined control sequence.\foreach ...reach\let \pgffor@assign@before@code=[lots more]"

When I replace the function with just the simple exp(x), the plot works. So what's wrong with this more complicated function?

Thanks


Solution

  • For the use in formula the logarithm function is ln not \ln

    \documentclass[11pt]{amsart}
    
    \usepackage{amssymb}
    \usepackage{amsmath}
    \usepackage{pgfplots}
    
    \begin{document}
    
    \begin{tikzpicture}
    \begin{axis}[domain=0:3,samples=100,yticklabels=\empty]
    \addplot+[no markers] {20-500*ln(0.998*exp(-x)+0.002+0*exp(x))-500*ln(0.998*exp(x)+0.002+0*exp(-x))};
    \end{axis}
    \end{tikzpicture}
    \end{document}
    

    enter image description here