1

I would like to plot $y = \sin^2(x) + \cos(x)$.

\documentclass[10pt]{amsart}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\begin{tikzpicture}
\begin{axis}[width=4in,axis on top,clip=false,
    axis lines=middle,
    xmin=-6.2832,xmax=7.4259,
    ymin=-1,ymax=1.25,
    restrict y to domain=-1:1.25,
    ticklabel style={font=\tiny},
    xtick={-1.0472, 1.0472},
    xticklabels={\makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\dfrac{\pi}{3}$, $\scriptstyle\dfrac{\pi}{3}$},
    xlabel=$x$,ylabel=$y$,
    ytick={-1, 1.25},
    yticklabels={$\scriptstyle-1$, $\scriptstyle\dfrac{5}{4}$},
    axis line style={latex-latex},
    enlargelimits={abs=0.25cm},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=201,domain=-6.2832:6.2832, dashed] {(sin(deg(x)))^2 + cos(deg(2*x))} ;


\end{axis}
\end{tikzpicture}

\end{document}

1 Answer 1

0

You have a "2" too many at line 29, which should be cos(deg(x)):

\documentclass[10pt]{amsart}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

    \begin{tikzpicture}
    \begin{axis}[width=4in,axis on top,clip=false,
    axis lines=middle,
    xmin=-6.2832,xmax=7.4259,
    ymin=-1,ymax=1.25,
    restrict y to domain=-1:1.25,
    ticklabel style={font=\tiny},
    xtick={-1.0472, 1.0472},
    xticklabels={\makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\dfrac{\pi}{3}$, $\scriptstyle\dfrac{\pi}{3}$},
    xlabel=$x$,ylabel=$y$,
    ytick={-1, 1.25},
    yticklabels={$\scriptstyle-1$, $\scriptstyle\dfrac{5}{4}$},
    axis line style={latex-latex},
    enlargelimits={abs=0.25cm},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]
    \addplot[samples=201,domain=-6.2832:6.2832, dashed] {(sin(deg(x)))^2 + cos(deg(x))} ;


    \end{axis}
    \end{tikzpicture}

\end{document}

Test

4
  • 1
    Can you provide complete code or at least code line, which you corrected?
    – Zarko
    Commented Aug 1, 2016 at 3:46
  • Alright, I edited my answer. Hopefully it's clear now.
    – Gipfeli
    Commented Aug 1, 2016 at 4:25
  • Unfortunately, not. Your code line is the same as in the question and it doesn't generate image which you show.
    – Zarko
    Commented Aug 1, 2016 at 4:38
  • Oops, I just see my typo. Sorry, and thank for proof-reading my answer.
    – Gipfeli
    Commented Aug 1, 2016 at 4:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .