# Incorrect plotting of e function using Tikz plot

I am trying to plot a couple functions in Latex, including an absolute and e function, these are depicted in the following image;

However using the code below, the image that results is:

What is going wrong?

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $t$,
ylabel = {$f(t)$},
]
%Below the red parabola is defined
domain=-0.5:0.5,
samples=100,
color=red,
]
{sqrt(abs(x))};
\addlegendentry{$\sqrt{|t|}$}
%Here the blue parabloa is defined
domain=-0.5:0.5,
samples=100,
color=blue,
]
{abs(x)};
\addlegendentry{$|t|$}
%Here the orange parabloa is defined
domain=-0.5:0.5,
samples=200,
color=orange,
]
{e^(abs(x)-1)};
\addlegendentry{$e^{|t|}-1$}
%Here the purple parabloa is defined
domain=-0.5:0.5,
samples=100,
color=purple,
]
{e^(abs(2*x)-1)};
\addlegendentry{$e^{|2t|}-1$}

\end{axis}
\end{tikzpicture}
\caption{M1} \label{fig:M1}
\end{figure}
\end{document}

• Welcome to TeX.SX! Please make your code compilable (MWE). – TeXnician Apr 6 '17 at 7:41
• @TeXnician Is it correct now? – Joel Apr 6 '17 at 7:49
• Now it is compilable. – TeXnician Apr 6 '17 at 7:55
• A couple of things:too few samples, giving you the blunt tip on $\sqrt{|t|}$; Don't you mean e^(abs(x))-1? That would be $\mathrm{e}^{|t|}-1$ as indicated, and would make sense as e^0=1 and you want orange_curve(0)=0, so orange_curve should be (e^x)-1 (superfluous brackets for emphasis) – Chris H Apr 6 '17 at 8:05
• Note also that with an even number of samples and a domain that is symmetric around 0, you will not get a sample exactly at x=0. So try 101 samples, instead of 100. – Torbjørn T. Apr 6 '17 at 9:12

At least your red plot can be improved by increasing the samples with:

\addplot [
domain=-0.5:0.5,
samples=1000,
color=red,
smooth,
]
{sqrt(abs(x))};


But pgfplots is right plotting your functions: the purple and orange one can not go to y-value 0 (manually calculating results in 1/e for x=0).

%Here the orange parabloa is defined
domain=-0.5:0.5,
samples=201,
color=orange,
smooth
]
{e^(abs(x))-1};
\addlegendentry{$e^{|t|}-1$}
%Here the purple parabloa is defined
\addlegendentry{$e^{|2t|}-1$}

• 5000 is a bit overkill, try 201. (Maybe more for sqrt(abs(x)).) – Torbjørn T. Apr 6 '17 at 9:15