2

I'm trying to make a parametric graph, but for some reason it doesn't work.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath,amsthm,amssymb}

\pgfplotsset{every axis/.append style={
                    axis x line=middle,    % put the x axis in the middle
                    axis y line=middle,    % put the y axis in the middle
                    axis line style={<->,color=blue}, % arrows on the axis
                    xlabel={$x$},          % default put x on x-axis
                    ylabel={$y$},          % default put y on y-axis
            }}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            xmin=-8,xmax=6,
            ymin=-8,ymax=6,
            grid=both,
            ]
            \addplot [domain=-3:3,samples=50]({2.5\sin^2(-5x)2^{\cos(\cos(4.28(2.3x)))}},{2.5\sin(\sin(-5x))\cos^2(4.28(2.3x))}); 
    \end{axis}
\end{tikzpicture}
\end{document}
egreg
  • 1,121,712
  • 2
    What are you trying to plot? The domain=-3:3,samples=50 is an option to \addplot which should be enclosed as [domain=-3:3,samples=50] and in your code\addplot has no argument giving it a file of data or a function to plot. \addplot [domain=-3:3,samples=50] {x}; for example will plot y=x from -3 to +3. – Dai Bowen Oct 21 '16 at 00:18
  • @DaiBowen an answer? :) – cmhughes Oct 21 '16 at 09:50
  • If I use the correct syntax for the functions to be plotted, I just get a black blob over the x-axis. – egreg Oct 21 '16 at 10:43
  • You're also making the mistake of using macros intended for typesetting (\cos,\sin) instead of the mathematical functions defined by pgf for calculations (cos,sin, no backslash). And finally, you need to explicitly add multiplication, so 5*x, not 5x. – Torbjørn T. Oct 21 '16 at 10:57

2 Answers2

2

The domain=-3:3,samples=50 is an option to \addplot which should be enclosed as [domain=-3:3,samples=50] and in your code\addplot has no argument giving it a file of data or a function to plot. \addplot [domain=-3:3,samples=50] {x}; for example will plot y=x from -3 to +3.

In order to plot parametric curves rather than giving {x}, \addplot should receive \addplot [domain=-3:3,samples=50]({x^3-3*x},{3*x^2-9}); or to work with some variable t rather than x (to me at least this feels more intuitive!), \addplot [domain=-3:3,samples=50,variable=\t]({t^3-3*t},{3*t^2-9}); will plot x(t)=t^3-3d and y(t)=3t^2-9 for t between -3 and 3.

See Plotting parametric curves, in particular cmhughes' answer for a full example of parametric plots with pgfplots.

Dai Bowen
  • 6,117
1

You shouldn't input the functions to be plotted in TeX syntax, but in a way that allows the computation.

Recall that cos and sin take their argument in degrees, so you have to transform the argument.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath,amsthm,amssymb}

\pgfplotsset{
  every axis/.append style={
    axis x line=middle,    % put the x axis in the middle
    axis y line=middle,    % put the y axis in the middle
    axis line style={<->,color=blue}, % arrows on the axis
    xlabel={$x$},          % default put x on x-axis
    ylabel={$y$},          % default put y on y-axis
  }
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  xmin=-5,xmax=5,
  ymin=-5,ymax=5,
  grid=both,
]
  \addplot[domain=-30:30,samples=100,variable=\t](%
    {2.5 * (sin(deg(-5*t)))^2 * 2^(cos(deg(cos(deg(4.28*2.3*t)))))},%
    {2.5 * (sin(deg(sin(deg(-5*t))))) * (cos(deg(4.28*2.3*t)))^2}%
  ); 
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Increasing the number of samples produces a big black blob.

egreg
  • 1,121,712