MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Patterns with conditions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116911] Re: Patterns with conditions
  • From: "Tony Harker" <a.harker at ucl.ac.uk>
  • Date: Fri, 4 Mar 2011 03:39:21 -0500 (EST)

Yes, you can do just as you say: SetAttributes[sinc, Listable].

With your form of the function, Mathematica is happy to wrap the listable function Sin[] round tab to produce a list of values, which it then divides item by item by tab to give the 0/0 problem. Once you define your function to be listable, the whole function will be taken inside the list and applied element by element to tab.

  Tony

]-> -----Original Message-----
]-> From: =C5 er=C3=BDch Jakub [mailto:Serych at panska.cz]
]-> Sent: 03 March 2011 10:58
]-> To: mathgroup at smc.vnet.net
]-> Subject: [mg116883] Patterns with conditions
]->
]-> 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[0]. 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[0]
]-> sinc[tab] Map[sinc, tab]



  • Prev by Date: Re: Filtering data from numerical minimization
  • Next by Date: Re: Alternative to DumpSave
  • Previous by thread: Re: Patterns with conditions
  • Next by thread: Re: Patterns with conditions