MathGroup Archive 2009

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

Search the Archive

Re: Re: Map[] and multiple args function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96290] Re: [mg96228] Re: [mg96198] Map[] and multiple args function
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 11 Feb 2009 05:18:01 -0500 (EST)
  • References: <20738936.1234177212952.JavaMail.root@m02>
  • Reply-to: drmajorbob at longhorns.com

Or, simpler:

foo[x_, y_, z_] := x + 2*y + 3*z
list = {{1, 2, 3}, {4, 5, 6}};

Total[foo @@@ list]

46

Bobby

On Tue, 10 Feb 2009 04:47:14 -0600, David Park <djmpark at comcast.net> wrote:

> You could do something like the following:
>
> Foo[x_, y_, z_] := x + 2*y + 3*z
>
> list = {{1, 2, 3}, {4, 5, 6}};
>
> Total@(Foo @@ # & /@ list)
> 46
>
> Plus @@ (Foo @@ # & /@ list)
> 46
>
>
> David Park
> djmpark at comcast.net
> http://home.comcast.net/~djmpark/
>
>
> From: sagrailo at gmail.com [mailto:sagrailo at gmail.com]
>
> 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?
>
> Thanks.
>
>
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: Re: Manipulating list of functions
  • Next by Date: Re: weather blog and ListStreamPlot sampling
  • Previous by thread: Re: Map[] and multiple args function
  • Next by thread: Re: Map[] and multiple args function