Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57472] Re: [mg57444] Re: [mg57377] Re: [mg57309] Applying a list of functions to a list of arguments
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 29 May 2005 01:03:30 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

f={f1,f2,f3};

#[a]&/@f

{f1(a),f2(a),f3(a)}

or

#@a&/@f

{f1(a),f2(a),f3(a)}


Bob Hanlon

> 
> From: Murray Eisenberg <murray at math.umass.edu>
To: mathgroup at smc.vnet.net
> Date: 2005/05/28 Sat AM 05:39:07 EDT
> Subject: [mg57472] [mg57444] Re: [mg57377] Re: [mg57309] Applying a list of 
functions to a list of arguments
> 
> This problem also reminds me of a simpler one:  Given
> 
>    f = {f1, f2, f3};
>    a = (* some number *)
> 
> what are nice ways of producing the following result?
> 
>    {f1[a], f2[a], f3[a]}
> 
> Th
> Wolf, Hartmut wrote:
> >>-----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: [mg57472] [mg57444] [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
> > 
> > 
> 
> -- 
> Murray Eisenberg                     murray at math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower      phone 413 549-1020 (H)
> University of Massachusetts                413 545-2859 (W)
> 710 North Pleasant Street            fax   413 545-1801
> Amherst, MA 01003-9305
> 
> 


  • Prev by Date: Re: Complex Oddity
  • Next by Date: Re: sorting complex number?
  • Previous by thread: Re: Re: Re: Applying a list of functions to a list of arguments
  • Next by thread: compilation problems on solaris