MathGroup Archive 2005

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

Search the Archive

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


  • Prev by Date: Re: Differences between recursions and limit
  • Next by Date: Re: 5.2 Install issues
  • Previous by thread: Re: writing a function with unknown number of paramters
  • Next by thread: Running ps2pdf from within Mathematica