MathGroup Archive 2009

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

Search the Archive

Re: Mapand multiple args function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96266] Re: Mapand multiple args function
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 10 Feb 2009 05:54:15 -0500 (EST)

On 2/9/09 at 5:33 AM, sagrailo at gmail.com wrote:

>I know this has to be FAQ, but I'm just not able to find an answer
>anywhere, so - here it goes:  I have a multiple-arguments function,
>say something like:

>Foo[x_, y_, z_] := x + 2*y + 3*z
>Now, I want to call this function number of times, over different
>sets of arguments, and then to sum results.  I thought about storing
>argument triplets into some kind of list, and then employing
>sequence of Map[] and Apply[] to get the job done.  After number of
>trials and errors, I came up with following piece of code doing the
>thing:

>Plus @@ Foo /@ {{1, 2, 3}, {4, 5, 6}} /. List -> Sequence
>but I even don't fully understand what's going here, and also I'm
>wondering is there a "better" way to accomplish this.  So - any
>suggestion?

Better always depends on what is meant by better. There are
alternatives. One alternative that is more compactly written
would be:

Total[Foo @@@ {{1, 2, 3}, {4, 5, 6}}]



  • Prev by Date: Re: Printing (v7)
  • Next by Date: JLink problem, Mathematica 6, OSX, Java SE 6 (64 bit).
  • Previous by thread: Re: WeatherData - many properties unavailable?
  • Next by thread: JLink problem, Mathematica 6, OSX, Java SE 6 (64 bit).