## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Sine 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

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?

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

Tags:

mas
Posts: 223
Joined: Thu Dec 04, 2008 4:39 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.
\documentclass{standalone}\usepackage{tikz}\usepackage{pgfplots} \begin{document}   \begin{tikzpicture}     \begin{axis}       \addplot [samples=200,smooth,no markers] {cos(deg(3*x))+0.5*sin(deg(x))+sin(deg(0.5*x))} ;     \end{axis}   \end{tikzpicture}\end{document}
Attachments graph.png (18.28 KiB) Viewed 4505 times

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

fruitfrisje
Posts: 10
Joined: Wed Dec 05, 2012 12:26 pm
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.

\documentclass[11pt,a4paper,twoside]{report}\usepackage{pgfplots} \begin{document}   \begin{tikzpicture}     \begin{axis}[       xlabel=$N$,       ylabel=$\Delta\sigma$,       xmin=0,       xmax=8,%     ymin=-3,%     ymax=3     ]       \addplot [samples=100,smooth,no markers,domain=0:7] {cos(deg(3*x))+0.5*sin(deg(x))+sin(deg(0.5*x))} ;     \end{axis}   \end{tikzpicture}\end{document}

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