0

This question already has an answer here:

I have been using LaTeX forever, but strangely just realized I've never had to plot a graph in it. The graph is seen here:

enter image description here

and the equations are here

enter image description here

I want to use

\usepackage{pgfplots}

However I am open to using other packages if you recommend any?

Thanks

marked as duplicate by Bobyandbob, CarLaTeX, Mensch, Stefan Pinnow, Phelype Oleinik Mar 11 '18 at 21:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

as starting point:

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

\begin{document}
    \begin{tikzpicture}
\begin{axis}[samples=60]
\addplot[blue, domain=0:pi] {cos(deg x)-1};
\addplot[green,domain=0:pi] {-sin(deg x)};
%
\addplot[blue, domain=pi:2*pi] {3*cos(deg x)+1};
\addplot[green,domain=pi:2*pi] {-3*sin(deg x)};
\end{axis}
    \end{tikzpicture}
\end{document}

where deg make conversion of argument x from radians to degrees (trigonometric functions are defined for degrees).

enter image description here

  • or you can write x r it will understand radians context with that, or change the trig format – percusse Mar 11 '18 at 20:56
  • @percusse, i simply forgot on this option :-(. thank you very much to remind me :-). but now i make short text, and receive error. i should repeat my test more carefully. – Zarko Mar 11 '18 at 20:59
0

Same output as Zarko's nice answer, but really piecewise functions with ifthenelse.

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

\begin{document}
    \begin{tikzpicture}
     \begin{axis}[samples=60]
     \addplot[blue, domain=0:2*pi] {ifthenelse(x<pi,cos(deg x)-1,3*cos(deg x)+1)};
     \addplot[green,domain=0:2*pi] {ifthenelse(x<pi,-sin(deg x),-3*sin(deg x))};
     \end{axis}
    \end{tikzpicture}
\end{document}

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