2

I just want to plot a function with some parameters which I want to be arguments of the function Referring to this answer I made my own code with my own function, but when I try to compile it says Undefined control sequence. What am I doing wrong?

\documentclass{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.16}
\begin{document}
    \begin{tikzpicture}[
            declare function={VMorse(\x, \De, \aval, \xre) = \De*(exp(-2*\aval*(\x-\xre))- 2*exp(-\aval*(\x-\xre)));},%
        ]
        \begin{axis}
            \addplot[domain=1:5] {VMorse(x, 2, 1, 0)};
        \end{axis}
    \end{tikzpicture}
\end{document}
4

White spaces! Do not use them in the arguments of the function

\documentclass{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.16}
\begin{document}
    \begin{tikzpicture}[
            declare function={VMorse(\x,\De,\aval,\xre)=\De*(exp(-2*\aval*(\x-\xre))- 2*exp(-\aval*(\x-\xre)));},%
        ]
        \begin{axis}
            \addplot[domain=1:5] {VMorse(x, 2, 1, 0)};
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

@marmot actually found this to be the solution in a previous question of mine

parametric line renders a mesh: how functions are parsed

  • 1
    Nice! Didn't expect it all, tikz manual should emphasise this peculiarity... – GiuTeX Feb 1 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.