LaTeX forum ⇒ Graphics, Figures & TablesSine Curve with variable Amplitude Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
fruitfrisje
Posts: 10
Joined: Wed Dec 05, 2012 12:26 pm

Sine Curve with variable Amplitude

Postby fruitfrisje » Mon May 20, 2013 4:47 pm

I'm trying to create an irregular sine curve that looks likes variable amplitude stress. I've tried the following code. It looks OK, but the shape of the curve is not fluent but it has sharp edges. Any one an idea?

  1. \documentclass[11pt,a4paper,twoside]{report}
  2. \usepackage{tikz}
  3. \usepackage{pgfplots}
  4.  
  5. \begin{document}
  6. \begin{tikzpicture}[scale=2]
  7. \draw [draw=black,thick,->] (0.00,0.00) -- (pi,0.00); % draw x-axis bottom
  8. \draw [draw=black,thick,->] (0.00,-2.00) -- (0.00,2.00); % draw y-axis bottom
  9. \draw [blue,domain=0:2*pi] plot (\x,{cos(\x*3 r)+0.5*sin(\x r)+sin(\x*0.5 r)});
  10. \end{tikzpicture}
  11. \end{document}

Tags:

mas
Posts: 222
Joined: Thu Dec 04, 2008 4:39 am

Postby mas » Tue May 21, 2013 3:47 am

Since you are already familiar with TikZ, use pgfplots to plot the graphs. It gives you more flexibility and features with plotting data and functions. Here is your reworked sample.
  1. \documentclass{standalone}
  2. \usepackage{tikz}
  3. \usepackage{pgfplots}
  4.  
  5. \begin{document}
  6. \begin{tikzpicture}
  7. \begin{axis}
  8. \addplot [samples=200,smooth,no markers] {cos(deg(3*x))+0.5*sin(deg(x))+sin(deg(0.5*x))} ;
  9. \end{axis}
  10. \end{tikzpicture}
  11. \end{document}
Attachments
graph.png
graph.png (18.28 KiB) Viewed 4219 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

fruitfrisje
Posts: 10
Joined: Wed Dec 05, 2012 12:26 pm

Postby fruitfrisje » Tue May 21, 2013 9:32 am

That works perfectly!

But now I am not being able to change the axis dimensions. The plot only goes to about 5 (x-axis) but I would like it to go to 8.

  1. \documentclass[11pt,a4paper,twoside]{report}
  2. \usepackage{pgfplots}
  3.  
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \begin{axis}[
  7. xlabel=$N$,
  8. ylabel=$\Delta\sigma$,
  9. xmin=0,
  10. xmax=8,
  11. % ymin=-3,
  12. % ymax=3
  13. ]
  14. \addplot [samples=100,smooth,no markers,domain=0:7] {cos(deg(3*x))+0.5*sin(deg(x))+sin(deg(0.5*x))} ;
  15. \end{axis}
  16. \end{tikzpicture}
  17. \end{document}


Edit: Nevermind, adding domain=0:7 did the trick (see code anove).


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests