MathGroup Archive 2006

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

Search the Archive

RE: Applying a list of 2D paramters to a mathematica function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68077] RE: [mg68041] Applying a list of 2D paramters to a mathematica function
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 21 Jul 2006 17:36:34 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Curry,

You want to use Apply, and there is a special construction that will map
Apply to the first level of a list. Check the Help for Apply where you will
find:

f @@@ expr is equivalent to Apply[f, expr, {1}].

So, for your case:

f[x_, y_] := x + y;
indices = {{a, b}, {c, d}, {e, f}};

f @@@ indices
{a + b, c + d, e + f}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: Curry Taylor [mailto:curry at 192.168.0.101]
To: mathgroup at smc.vnet.net



         I have (for simplicity) something like this:

         f[x_, y_] := x+y;

         I want to use this function for a variety of parameters in a list:

         indices = {{a,b}, {c,d}, {e,f}, ..}

         so that I get

         {a+b, c+d, e+f, ..}

         Doing the intuitive thing (for me)

         f /@ indices

         results in

         {f[{a, b}], f[{c, d}], f[{e, f}], ..}

         but what I want is

         {f[a, b], f[c, d], f[e, f], ..}

         and that's not what I'm getting. I have tried using Flatten, pure
functions (Slot # and &), different Map functions, nesting at parameters
(like {1} and {2}), and other things but I just can't seem to get what I'm
after. Any help please?

         Thank you,

Curry



  • Prev by Date: Re: Programming with options.
  • Next by Date: Re: Applying a list of 2D paramters to a mathematica function
  • Previous by thread: Re: Applying a list of 2D paramters to a mathematica function
  • Next by thread: Re: Applying a list of 2D paramters to a mathematica function