Graphics, Figures & TablesSine Curve with variable Amplitude

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

Sine Curve with variable Amplitude

Post by fruitfrisje »

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?

Code: Select all

\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}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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

Sine Curve with variable Amplitude

Post by mas »

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.

Code: Select all

\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
graph.png (18.28 KiB) Viewed 7121 times

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
fruitfrisje
Posts: 10
Joined: Wed Dec 05, 2012 12:26 pm

Sine Curve with variable Amplitude

Post by fruitfrisje »

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.

Code: Select all

\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).
Post Reply