       Re: Patterns with conditions

• To: mathgroup at smc.vnet.net
• Subject: [mg116915] Re: Patterns with conditions
• From: David Skulsky <edskulsky at gmail.com>
• Date: Fri, 4 Mar 2011 03:40:04 -0500 (EST)

```Make your function listable:

SetAttributes[sinc, Listable]
sinc[tab]

{1, (3 Sin[\[Pi]^2/3])/\[Pi]^2, (3 Sin[(2 \[Pi]^2)/3])/(2 \[Pi]^2),
Sin[\[Pi]^2]/\[Pi]^2, (3 Sin[(4 \[Pi]^2)/3])/(4 \[Pi]^2), (
3 Sin[(5 \[Pi]^2)/3])/(5 \[Pi]^2), Sin[2 \[Pi]^2]/(2 \[Pi]^2)}

David

On Thursday, March 3, 2011 3:05:27 AM UTC-8, =C5 er=C3=BDch Jakub wrote:
> Dear Mathematica group,
> I'm playing with function definitions and patterns based multiple definition of the function. I have defined this function:
> sinc[x_ /; x == 0] := 1;
> sinc[x_] := Sin[\[Pi] x]/(\[Pi] x);
>
> (I know, that Mathematica has Sinc function defined, it's just the test.)
>
> It works fine for let's say sinc[\[Pi]], even for sinc. But if I define the table:
>
> tab = {0, \[Pi]/3, \[Pi]/2, \[Pi] 2/3, \[Pi], \[Pi] 4/3, \[Pi] 5/3,
>    2 \[Pi]};
>
> and I let my function evaluate the results sinc[tab], it returns error messages:
> Power::infy: Infinite expression 1/0 encountered. >> and
> Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.
>>
>
> I can understand, that "tab" doesn't fit to pattern condition /; x==0, also I know, that it is possible to Map my function to table
> Map[sinc, tab] and it works fine.
>
> I can imagine solution with IF[x==0,1, Sin[\[Pi] x]/(\[Pi] x), but my question is: Is it possible to make my function fully Listable using just pattern conditions?
>
> Thanks for responses
>
> Jakub
>
> P.S. Code in one block for easy copying:
>
> sinc[x_ /; x == 0] := 1;
> sinc[x_] := Sin[\[Pi] x]/(\[Pi] x);
> tab = {0, \[Pi]/3, \[Pi] 2/3, \[Pi], \[Pi] 4/3, \[Pi] 5/3, 2 \[Pi]};
> sinc[\[Pi]]
> sinc
> sinc[tab]
> Map[sinc, tab]

```

• Prev by Date: Re: How to suppress (hide) RunThrough window under Windows?
• Next by Date: Re: Patterns with conditions
• Previous by thread: Re: Patterns with conditions
• Next by thread: Re: Patterns with conditions