I'm trying to create a piecewise plot in tikzpicture. Trying to emulate the example from this answer Plotting a piecewise function didn't work for me, and I don't understand why this code isn't working.
\documentclass[11pt, letterpaper]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
declare function={
func(\x)= (\x<=0) * ((0.5)*exp(\x)) +
and(\x>0) * (1-(0.5)*exp(-\x))
;
}
]
\begin{axis}[
axis x line=middle, axis y line=middle,
ymin=0, ymax=1, ytick={0,0.5,1}, ylabel=$F_{X-Y}(t)$,
xmin=-5, xmax=5, xtick={-5,...,5}, xlabel=$t$,
]
\addplot[blue, domain=-5:5, smooth]{func(x)};
\end{axis}
\end{tikzpicture}
\end{document}
Any help would be greatly appreciated!


and. Usefunc(\x)= (\x<=0) * ((0.5)*exp(\x)) + (\x>0) * (1-(0.5)*exp(-\x));. – Feb 19 '20 at 03:51