## LaTeX forum ⇒ Math & Science ⇒ Drawing 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

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

Hope you can help me because i need it in few days, there are picture how it should look: plot.jpg (47.71 KiB) Viewed 15970 times

and this are functions: formula.jpg (15.87 KiB) Viewed 15970 times

Thanks.

Tags:

Stefan Kottwitz
Posts: 9513
Joined: Mon Mar 10, 2008 9:44 pm
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:

\documentclass[border=10pt]{standalone} \usepackage{pgfplots}\pgfplotsset{%   every tick label/.append style = {font=\tiny},   every axis label/.append style = {font=\scriptsize}}\begin{document}\begin{tikzpicture}   \begin{axis}[grid=major, xmin=0, xmax=3, ymin=-1.1, ymax=1.1,     xlabel=$t$, ylabel={$x(t), y(t)$},     xtick = {0,0.5,...,3}, ytick = {-1,-0.5,...,1},     scale=0.3, restrict y to domain=-1:1]     \addplot[blue, samples=100, smooth, unbounded coords=discard]       plot (\x, { 1 + 2 * \x)*exp(-2*\x) * sin(280* 3.14 * \x) });     \addplot[red, dashed, samples=100, smooth]       plot (\x, { (1+2*\x) * exp(-2*\x) } );     \addplot[red, dashed, samples=100, smooth]       plot (\x, { -(1+2*\x) * exp(-2*\x) } );   \end{axis}\end{tikzpicture}\end{document} plot.png (15.7 KiB) Viewed 17496 times

Stefan

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

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

Then the Graph fits to the so called envelope.

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

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

Stefan Kottwitz
Posts: 9513
Joined: Mon Mar 10, 2008 9:44 pm
Hi GKS,

thank you for the correction!

And welcome to the forum,

Stefan