I am trying to declare the sinc
-function for usage in tikz
. I tried two different ways:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}
\tikzmath{
function sincm(\x) {
if abs(\x) < 0.001 then {
return 1.0;
} else {
return sin(\x r)/\x;
};
};
}
\pgfmathdeclarefunction{sinc}{1}{%
\pgfmathparse{%
abs(#1)<0.001 ? 1 : sin(#1 r)/#1%
}%
}
\draw (-1,0) -- (1,0);
\draw[domain=0:0.5, samples=1000] plot (\x, {sincm(\x*20)});
\draw[domain=0:0.5, samples=1000, red, dotted] plot (\x,{sinc(\x*20)});
\end{tikzpicture}
\end{document}
Both ways yield the same result. I would like to use \pgfmathdeclarefunction
variante, first of all to be able to declare this function globally, maybe even for several tikz
-pictures. However, if I set the start of the plotting domain to zero:
\draw[domain=0:0.5, samples=1000, red, dotted] plot (\x,{sinc(\x*20)});
I get the Error Package PGF Math Error: You've asked me to divide '0,0' by '0.0'
. Somehow, in this case, the ifthenelse
-structure in my declaration of sinc
does not seem to work?