LaTeX forum ⇒ Math & ScienceDrawing function in tikzpicture Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
m3talac
Posts: 1
Joined: Sun Jan 10, 2016 6:31 am

Drawing function in tikzpicture

Postby m3talac » Sun Jan 10, 2016 6:43 am

I have to draw function with \plot but it says "Dimension too large", this is my code:
  1. \begin{tikzpicture}
  2. \begin{axis}[grid=major, xmin=0, xmax=3, ymin=-1.5, ymax=1.5, xlabel=$t$, ylabel=$x(t), y(t)$, scale=0.3]
  3. \plot[blue] plot[samples=100, smooth] expression{(1 + 2 * x)*exp(-2*x) * sin(280* 3.14 * x)};
  4. \plot[red, dashed] plot[samples=100, smooth] expression{ (1+2*x) * exp(-2*x)};
  5. \end{axis}
  6. \end{tikzpicture}


Hope you can help me because i need it in few days, there are picture how it should look:

plot.jpg
plot.jpg (47.71 KiB) Viewed 950 times


and this are functions:

formula.jpg
formula.jpg (15.87 KiB) Viewed 950 times


Thanks.

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8527
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Jan 10, 2016 11:59 am

Hi,

welcome to the forum!

I would use pgfplots for this. Have a look at the pgfplots gallery for examples.

To avoid that "Dimension too large" error, you can restrict the y value as I do here:

  1. \documentclass[border=10pt]{standalone}
  2. \usepackage{pgfplots}
  3. \pgfplotsset{%
  4. every tick label/.append style = {font=\tiny},
  5. every axis label/.append style = {font=\scriptsize}
  6. }
  7. \begin{document}
  8. \begin{tikzpicture}
  9. \begin{axis}[grid=major, xmin=0, xmax=3, ymin=-1.1, ymax=1.1,
  10. xlabel=$t$, ylabel={$x(t), y(t)$},
  11. xtick = {0,0.5,...,3}, ytick = {-1,-0.5,...,1},
  12. scale=0.3, restrict y to domain=-1:1]
  13. \addplot[blue, samples=100, smooth, unbounded coords=discard]
  14. plot (\x, { 1 + 2 * \x)*exp(-2*\x) * sin(280* 3.14 * \x) });
  15. \addplot[red, dashed, samples=100, smooth]
  16. plot (\x, { (1+2*\x) * exp(-2*\x) } );
  17. \addplot[red, dashed, samples=100, smooth]
  18. plot (\x, { -(1+2*\x) * exp(-2*\x) } );
  19. \end{axis}
  20. \end{tikzpicture}
  21. \end{document}


plot.png
plot.png (15.7 KiB) Viewed 2476 times


Stefan
Site admin

GKS
Posts: 1
Joined: Fri Jul 08, 2016 9:35 pm

Postby GKS » Fri Jul 08, 2016 9:44 pm

Hello,

I would like to mention, that there is a little mistake/typo in your code, Stefan_K. It should be
  1. sin(180* 3.14 * \x)

Then the Graph fits to the so called envelope.

For better convenience
  1. \documentclass[border=10pt]{standalone}
  2. \usepackage{pgfplots}
  3. \pgfplotsset{%
  4. every tick label/.append style = {font=\tiny},
  5. every axis label/.append style = {font=\scriptsize}
  6. }
  7. \begin{document}
  8. \begin{tikzpicture}
  9. \begin{axis}[grid=major, xmin=0, xmax=3, ymin=-1.1, ymax=1.1,
  10. xlabel=$t$, ylabel={$x(t), y(t)$},
  11. xtick = {0,0.5,...,3}, ytick = {-1,-0.5,...,1},
  12. scale=0.3, restrict y to domain=-1:1]
  13. \addplot[blue, samples=100, smooth, unbounded coords=discard]
  14. plot (\x, { 1 + 2 * \x)*exp(-2*\x) * sin(180* 3.14 * \x) });
  15. \addplot[red, dashed, samples=100, smooth]
  16. plot (\x, { (1+2*\x) * exp(-2*\x) } );
  17. \addplot[red, dashed, samples=100, smooth]
  18. plot (\x, { -(1+2*\x) * exp(-2*\x) } );
  19. \end{axis}
  20. \end{tikzpicture}
  21. \end{document}


Greeetings GKS
Attachments
plotversion2.png
corrected plot
plotversion2.png (28.6 KiB) Viewed 1827 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 8527
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Jul 08, 2016 9:58 pm

Hi GKS,

thank you for the correction!

And welcome to the forum,

Stefan
Site admin


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 5 guests