MathGroup Archive 2005

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

Search the Archive

Re: Applying a list of functions to a list of arguments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57340] Re: [mg57309] Applying a list of functions to a list of arguments
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 25 May 2005 06:02:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Derek,

For combining two equal length lists, I always think of the Inner command.

funclist = {f1, f2, f3};
arglist = {a1, a2, a3};

Inner[#1[#2] &, funclist, arglist, List]
{f1[a1], f2[a2], f3[a3]}

Inner has a default argument of Plus for the 4'th argument but, in this
case, we just change it to List. (Unless you want to sum the resulting
functions.)

For multiple arguments, you could use...

funclist = {f1, f2, f3};
arglist = {{a1, a2}, {b1, b2}, {c1, c2}};

MapThread[Apply[#1, #2] &, {funclist, arglist}]
{f1[a1, a2], f2[b1, b2], f3[c1, c2]}


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



From: D M Yates [mailto:yatesd at mac.com]
To: mathgroup at smc.vnet.net


I have a list of functions, and a list of arguments:

For example,
f = {f1, f2, f3}
a = {a1,a2,a3}

I would like to return
{f1[a1],f2[a2],f3[a3]}

I thought this should easy, but am stumped. Obviously the lists are of
equal, but arbitrary length, and the arguments may or may not be atomic
expressions. In my particular case, the arguments are likely to be
combinations of Real, and List[Real,...], but I hope this is
irrelevant.

Any suggestions?

Many thanks,

Derek Yates





  • Prev by Date: Re: Log function
  • Next by Date: Re: MathLink and GUIKit
  • Previous by thread: Re: Applying a list of functions to a list of arguments
  • Next by thread: Re: Re: Applying a list of functions to a list of arguments