0

I'm relatively new to LaTeX and as a result of playing around with it in sharelatex, I've started a few pages on calculus. I want to render this graph:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[ 
    xlabel=$x$,
    ylabel={$f(x) = sin(x)$}
  ] 
    \addplot {sin(x)}; 
  \end{axis}
\end{tikzpicture}\\

\end{document}

but it renders a wrong one, a graph I used before (f(x) = x/2).

How can I fix this?

10
  • 1
    Welcome to TeX.SE. As it stands, your question is not answerable. Please add the full, compilable code, not only fragments
    – user31729
    May 5 '17 at 20:54
  • Welcome! Please edit your code to provide a complete minimal example which reproduces the problem when we compile it. Are you sure that you don't just have an error so that the compilation of the new document does not succeed? Off-topic: don't use \\ for line breaks outside special environments such as tabular and array.
    – cfr
    May 5 '17 at 20:55
  • How do I conviniently make line breaks, then?
    – WzYDWzt
    May 5 '17 at 20:57
  • 1
    to see sinus function you should define domain. for example \addplot[domain=-180:180] {sin(x)};
    – Zarko
    May 5 '17 at 20:57
  • @WzYDWzt: Your code does not show that you use f(x) = x/2 ....
    – user31729
    May 5 '17 at 20:57
2

Completing your code to MWE and defining domain for sin(x) I obtain:

enter image description here

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel=$x$,
    ylabel={$f(x) = \sin(x)$}
  ]
    \addplot[domain=-180:180] {sin(x)};
  \end{axis}
\end{tikzpicture}
\end{document}

For more smooth curve you can define number of samples or add option smooth to addplot.

2

A few things:

Use \sin instead of sin

The sin function uses degrees, not radians

The samples option indicates at how many points the function should be evaluated.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[ 
    xlabel=$x$,
    ylabel={$f(x) = \sin(x)$}
  ] 
    \addplot[samples=200] {sin(180*x/3.14159)}; 
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

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.