1

I want to draw two dashed red line like the one in the second figure.

\documentclass{minimal}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
     \draw[->] (-0.2,0) -- (4.5,0) node[right] {$x$};
     \draw[->] (0,-1.2) -- (0,2.5) node[above] {$f(x)$};
     \draw[dash pattern=on 0pt off 2\pgflinewidth,line cap=round,line width=0.5mm,color=blue,domain=0:4,samples=100]  plot (\x,{1+ sin(10*\x r)*e^(-\x)})  ;
\end{tikzpicture}

\end{document}

Desirable figure

XJ.C
  • 303
  • Unrelated comment: in general, don't use minimal, but article. See https://tex.stackexchange.com/questions/42114/why-should-the-minimal-class-be-avoided – Torbjørn T. Apr 09 '18 at 12:27

1 Answers1

3

The line you want, is the "line that surrounding" your initial function (I don't know the name).

The sin(x) function is always between -1 and 1... So, math says that:

 1+ sin(10*\x r)*e^(-\x)

will always be between

1+ (+1)*e^(-\x) 

and

1+ (-1)*e^(-\x)


\documentclass{minimal}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
     \draw[->] (-0.2,0) -- (4.5,0) node[right] {$x$};
     \draw[->] (0,-1.2) -- (0,2.5) node[above] {$f(x)$};
     \draw[dash pattern=on 0pt off 2\pgflinewidth,line cap=round,line width=0.5mm,color=blue,domain=0:4,samples=100]  plot (\x,{1+ sin(10*\x r)*e^(-\x)})  ;
     \draw[dash pattern=on 0pt off 2\pgflinewidth,line cap=round,line width=0.5mm,color=red,dashed,thin,domain=0:4,samples=100]  plot (\x,{1+e^(-\x)})  ;
      \draw[dash pattern=on 0pt off 2\pgflinewidth,line cap=round,line width=0.5mm,color=red,dashed,thin,domain=0:4,samples=100]  plot (\x,{1-e^(-\x)})  ;
\end{tikzpicture}

\end{document}

enter image description here

koleygr
  • 20,105