[Tex/LaTex] plotting exp(x) in tikz

mathtoolsplottikz-pgf

I am trying to plot a function using tikz. Unfortunately I cannot use pgfplot because when I open the pgfplot package it collides with already existing latex drawing and plot codes used with tikz. Here is the code,

 \begin{tikzpicture}
 \draw[->] (-3,0) -- (4.2,0) node[right] {$x$};
 \draw[->] (0,-3) -- (0,4.2) node[above] {$y$};
 \draw[scale=0.7,domain=-3:3,smooth,variable=\x,blue] plot ({\x},  {1/(1+exp((-\x)/0.6))});
 \end{tikzpicture}

When I want to sharpen the step of the curve, I just decrease the number 0.6 to 0.2 or whatever. However, when I set this function with 0.2, I am getting error message that dimension too large. Is it possible to fix it with tikz?

Best Answer

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
You wish to plot 
\[f(x)~=~\frac{1}{1+\exp(-x/\alpha)}~=~\frac{1}{1+\exp(-2a\,x)}\]
with $a=1/(2\alpha)$. However,
\[f(x)~=~\frac{\exp(a\,x)}{\exp(a\,x)+\exp(-a\,x)}
~=~\frac{1}{2}\,\frac{\cosh(a\,x)+\sinh(a\,x)}{\cosh(a\,x)}
~=~\frac{1}{2}\,\left[1+\tanh(a\,x)\right]\;.\]
\begin{tikzpicture}
 \draw[->] (-3,0) -- (4.2,0) node[right] {$x$};
 \draw[->] (0,-3) -- (0,4.2) node[above] {$y$};
 \draw[scale=0.7,domain=-3:3,smooth,variable=\x,blue] plot ({\x}, 
 {exp(2.5*\x)/(exp(2.5*\x)+exp(-2.5*\x))});
\end{tikzpicture}
\begin{tikzpicture}
 \draw[->] (-3,0) -- (4.2,0) node[right] {$x$};
 \draw[->] (0,-3) -- (0,4.2) node[above] {$y$};
 \draw[scale=0.7,domain=-3:3,smooth,variable=\x,red] plot ({\x}, 
 {0.5*(1+tanh(2.5*\x))});
 \end{tikzpicture}
\end{document}