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: [mg57377] Re: [mg57309] Applying a list of functions to a list of arguments
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Thu, 26 May 2005 04:31:21 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: D M Yates [mailto:yatesd at mac.com] 
To: mathgroup at smc.vnet.net
>Sent: Tuesday, May 24, 2005 11:13 AM
>Subject: [mg57377] [mg57309] Applying a list of functions to a list of arguments
>
>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
>
>

This is indeed a FAQ. 

If you like to consider your list of arguments as a list of argument
lists (of one argument here):

In[8]:= aa = Partition[a,1]
Out[8]= {{a1}, {a2}, {a3}}

then 

In[9]:= MapThread[Apply,{f, aa}]
Out[9]= {f1[a1], f2[a2], f3[a3]}


else 

In[10]:= MapThread[#1@#2&,{f, a}]
Out[10]= {f1[a1], f2[a2], f3[a3]}

--
Hartmut Wolf


  • Prev by Date: Re: Applying a list of functions to a list of arguments
  • Next by Date: Re: Formating with TableForm
  • 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