Re: writing a function with unknown number of paramters

*To*: mathgroup at smc.vnet.net*Subject*: [mg60569] Re: writing a function with unknown number of paramters*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Tue, 20 Sep 2005 05:20:08 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On 9/19/05 at 4:45 AM, someonekicked at comcast.net (Someonekicked) wrote: >I wanna write a function that can take an unknown number of >parameters in mathematica, how I can do that?? >For example, The built-in function Plot, >Plot[{f1,f2,f3. }, {x, xmin, xmax}] >can take an unknown number of functions then plot them. Note, there is a difference between a function with an unknown number of arguements and a function accepting a List of unknown length. Suppose I wanted to get the trace of several matrices. One way would be myTr[x_]:=Tr/@x Generate some data and test matA = Table[Random[], {3}, {3}]; matB = Table[Random[], {4}, {4}]; myTr[{matA, matB}] {1.4689092118145766, 0.6890047681388858} An alternate means of achieve exactly the same thing would be to allow an arbitrary number of matrices as arguements to the function, i.e., myTr2[x__]:=Tr/@{x} myTr2[matA, matB] {1.4689092118145766, 0.6890047681388858} -- To reply via email subtract one hundred and four