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: [mg57424] Re: [mg57309] Applying a list of functions to a list of arguments
  • From: D M Yates <yatesd at mac.com>
  • Date: Fri, 27 May 2005 04:57:29 -0400 (EDT)
  • References: <786acfdc8ee4d17443dad387c58c6a91@mac.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Many thanks to the many people who have provided solutions to my query. 
The solutions were all variations on two themes, and somewhat 
surprisingly, one of the two solutions is actually only a partial 
solution.

Partial Solution:
~~~~~~~~~~~~
Inner[Compose , f , a , List]    (or a similar suggestion of 
Inner[#1[#2]& , f , a , List]  )

This works fine when the arguments are atomic, but

f = { f1 , f2 , f3 }
a = { {a1,a2,a3} , {b1,b2,b3} , {c1,c2,c3} }

returns

{{f1[a1], f2[b1], f3[c1]}, {f1[a2], f2[b2], f3[c2]}, {f1[a3], f2[b3], 
f3[c3]}}

instead of the desired

{ f1[{a1,a2,a3}] , f2[{b1,b2,b3}], f3[{c1,c2,c3}] }

I presume this is because Inner is designed for manipulating tensors, 
where the observed behaviour is desired.

Complete Solution:
~~~~~~~~~~~~~~
MapThread[ #1[#2]&, {f,a} ]

which indeed returns the desired result for both atomic lists and lists 
of lists.

Derek Yates


On 23 May 2005, at 10:24pm, D M Yates wrote:

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: How to get decent quality plots.
  • Next by Date: Re: A.I for mathematica
  • Previous by thread: Re: Re: Applying a list of functions to a list of arguments
  • Next by thread: Re: Re: Re: Applying a list of functions to a list of arguments