0

Can anyone plot the function

enter image description here

for me as in the screenshot blew ?

enter image description here

I need help, I can not even know how to start or to build a MWE.

1 Answers1

4

Note that you have to start at some point >0 since exp(-1/x) is undefined at x=0.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[axis lines=center,domain=-1:1.75,xlabel={$t$},
    ymin=-.1,% to prevent line getting cropped at y=0
    height=4cm,width=8cm]
  \addplot[samples=2,dashed] {1};
  \addplot[domain=-1:0.001,samples=2,color=black,ultra thick] {0};
  \addplot[domain=0.001:1.5,samples=50,color=black,ultra thick] {exp(-1/x};
\end{axis}
\end{tikzpicture}%

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • To evaluate t in the domain=-1:2 you can use you can specify the equation using {(x<=0)*0 + (x>0)*exp(-1/x)}. This skips x=0. For evaluation in more than two domains see here: http://tex.stackexchange.com/q/182505. – Ross Dec 03 '16 at 06:29
  • What a nice thing, but, what if you want to plot the sine or cosine function? I tried but didn't get success. – UnPerrito Dec 03 '16 at 06:41
  • This works, but how can I draw functions in latex ?! I tried many times but I failed @John – Hussein Eid Dec 03 '16 at 15:38
  • 1
    Read the tikz manual section on Syntax for Mathematical Expressions:starting on page 926. – John Kormylo Dec 03 '16 at 15:44