2

There is parametrically defined function. enter image description here I try to plot this function with PGFPlots like this:

\documentclass{article}
\usepackage{pgfplots}

\newcommand\xfunc[7]{2*#4*ln((1/2)* 
(#2*cos(#3)^2*#1*#5*#6*#7+2*#4)/#4)/(#5*#6*#7*cos(#3))}
\newcommand\yfunc[7]{ln((1/1962)*  
(10*sqrt(#5)*sin(#3)^(3/2)*sqrt(#7)*sqrt(#6)*#2*sin((3/20)*
sqrt(218)*sqrt(#5)*sqrt(sin(#3))*sqrt(#7)*sqrt(#6)*#1/sqrt(#4))+
3*sqrt(#4)*sqrt(218)*cos((3/20)*sqrt(218)*sqrt(#5)*sqrt(sin(#3))*
sqrt(#7)*sqrt(#6)*#1/sqrt(#4)))^2/#4)*#4/(#5*sin(#3)*#7*#6)}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel = {$x$},
    ylabel = {$y$},
    variable = \t,
    samples = 200]
  \addplot[domain=0:0.14,trig format=rad]
   (\xfunc{t}{1}{0.79}{0.8}{0.3}{1.2}{3.5*10^(-3)},
    \yfunc{t}{1}{0.79}{0.8}{0.3}{1.2}{3.5*10^(-3)});
  \end{axis}
\end{tikzpicture}
\end{document}

Expressions were copied from Maple source. All parameter variables were replaced by #1,#2,...,#7 tokens accordingly. And for preventing known issue with trigonometric functions arguments I used trig format=rad option. But I got this:

enter image description here

What am I doing wrong?

I have tried to maximum simplify the functions but the result was not much better.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\newcommand\xfunc[1]{1804.15*ln(0.39e-3*#1+1.00)}
\newcommand\yfunc[1]{893.81*ln(0.64e-3*(0.21*sin(0.74e-1*#1)
+39.62*cos(0.74e-1*#1))^2)}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel = {$x$},
    ylabel = {$y$},
    variable = \t,
    samples = 200]
  \addplot[domain=0:0.14,trig format=rad]({\xfunc{t}},{\yfunc{t}});
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    This is most probably due to numerical precison of the math engine. It looks exceedingly complicated. However you have a lot of redundant operations such as square roots can be grouped and logarithms can be combined. Also pgfplots understands scientific notation such as 3.5e-3 which would also save some precision. – percusse Apr 12 '18 at 19:24
  • I have tried to simplify my example without result. See edited post. – Konstantin Apr 13 '18 at 3:46
2

This is not exactly an answer, but a comment with an image.

I think the problem is the precision of TeX. One way to circumvent this would be to use Lua for the math calculation, which could be done by adding compat=1.12 (or a higher level) to your preamble and compiling with LuaLaTeX. Is this an option?

(This still is not the result you are expecting I guess, because the plot does not start at (0,0), but that hopefully just comes from a typo in the parameters so something other rather trivial.)

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % use this `compat' level or higher to use the Lua backend for
        % calculation of the functions
        % (which of course only works when you are compiling with LuaLaTeX)
        compat=1.12,
        % define some functions we want to calculate using LuaLaTeX
        /pgf/declare function={
            f(\x) = 1804.15*ln(0.39e-3*\x+1.00);
            g(\x) = 893.81*ln(0.64e-3*(0.21*sin(0.74e-1*\x) + 39.62*cos(0.74e-1*\x))^2);
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel={$x$},
        ylabel={$y$},
        samples=201,
        /pgf/number format/fixed,
    ]
        \addplot [domain=0:0.14,trig format=rad] ({f(x)},{g(x)});
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

  • Thanks for the answer. I can't compile with LuaLaTex your example right now but have found solution of my issue. I export plot data from Maple to data file and then \addplot from file. – Konstantin Apr 13 '18 at 6:22
  • That would have been my recommendation, if data are already available from another calculation program. – Stefan Pinnow Apr 13 '18 at 6:30

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.