I am using this method for Defining a Piecewise Function for PGFplots and want to specifically define the function value at the endpoint to be 1, not 0. When I change the < in the and to <= I get Illegal unit of measure (pt inserted)
This MWE produces this output but should have the black circle at (1,1) when it works properly.
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\newcommand{\pLabel}{
$p(x)=
\begin{cases}
x & 0 < x {\textcolor{red}{{}\leq{}}} 1\\
0 & \text{otherwise}
\end{cases}$
}
\tikzstyle{MyStyle}=[domain=-0.5:1.5, samples=100, ultra thick,blue]
\tikzstyle{pLabelStyle}=[above, yshift=25ex, xshift=-28ex]
\pgfmathdeclarefunction{p}{1}{%
\pgfmathparse{(and(#1>0, #1<1)*#1)}% This compiles with the "<"
%\pgfmathparse{(and(#1>0, #1<=1)*#1)}% This is what I want: note the "<="
}
% Compute point of interest
\newcommand*{\XValue}{1}%
\pgfmathsetmacro{\QatXValue}{p(\XValue)}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[MyStyle]{p(x)} node [pLabelStyle] {\pLabel};
\fill (axis cs: \XValue,\QatXValue) circle (4pt)
node [right, yshift=1.0ex] {$(1,p(1))$};
\end{axis}
\end{tikzpicture}
\end{document}
Is there a simple fix?
pgfmathuser (used it once), but did you try using ">" and "not"? (I know, I know, this is trivial, but maybe this helps...?) – mbork Jul 19 '11 at 05:51