Christophe Jorssen | 2 Nov 2008 20:35
Picon
Favicon

A new pgfmath operator: sinc

Hello all,

Here is the code for the sinus cardinalis (sinc) function (see 
http://en.wikipedia.org/wiki/Sinc_function), adding it to the pgfmath 
parser. The argument is in radian.

But... It does not work and I don't understand why...

Thanks in advance for your help.

Christophe

\documentclass{minimal}

\usepackage{tikz,pgfplots}

\begin{document}

\makeatletter
\pgfmathdeclarefunction{sinc}{1}{%
   \begingroup%
     \expandafter\pgfmath <at> x#1pt\relax
     \ifdim\pgfmath <at> x=0pt\relax
       \def\pgfmathresult{1}%
     \else
% First convert to radians x-> x r
       \pgfmathrad <at> {#1}%
% Take the sine x r -> sin(x r)
       \pgfmathsin <at> {\pgfmathresult}%
% Divide by the argument sin(x r)/x
       \pgfmathdivide <at> {\pgfmathresult}{#1}%
     \fi
     \pgfmath <at> smuggleone\pgfmathresult%
   \endgroup}

\begin{tikzpicture}
   \begin{axis}[xlabel=$x$,ylabel=$f(x)$,name=an axis]
     \addplot plot[domain=-10:10] (\x,{sinc(\x r)});
     \addplot plot[domain=-10:10] (\x,{sin(\x r)/\x});
   \end{axis}
\end{tikzpicture}

\end{document}

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Gmane