       Re: Giving several functions the same argument

• To: mathgroup at smc.vnet.net
• Subject: [mg109605] Re: Giving several functions the same argument
• From: cinnabar <kolbasa.sapiens at gmail.com>
• Date: Sat, 8 May 2010 07:05:16 -0400 (EDT)
• References: <hs0pkd\$dmm\$1@smc.vnet.net>

```On 7 =D0=BC=D0=B0=D0=B9, 12:22, Simon Pearce <Simon.Pea... at nottingham.ac.uk> wrote:
> Hi Mathgroup,
>
> I have a list of pure functions, which I wish to apply to the same
> argument. I can't seem to be able to thread the list of functions over
> the argument in a simple way, all the commands like Apply and Map etc
> take a single function. I can do it using Table and Part, but it seemed
> like there should be a simple command that I'm missing.
>
> For example:
>
> In:= functs = {Sin[#1] &, Cos[#1] &};
>
> In:= functs[x]
>
> Out= {Sin[#1] &, Cos[#1] &}[x]
>
> I want to get the result {Sin[x],Cos[x]} out, without having to use
> something of the form:
>
> In:= Table[functs[[i]][x], {i, 1, 2}]
>
> Out= {Sin[x], Cos[x]}
>
> Which seems like it'd be less efficient when I try and use it on long
> lists of functions.
>
> Thanks,
>
> Simon

Hi, Simon
The problem is you are applying a list to an argument, not a pure
function
Correct way is:

In:= {Sin[#], Cos[#]} &[x]

Out= {Sin[x], Cos[x]}
i.e. making one pure function with a list of bodies

Best Regards,
Roman

```

• Prev by Date: Re: Giving several functions the same argument
• Next by Date: Re: HoldFirst, Unevaluated
• Previous by thread: Re: Giving several functions the same argument
• Next by thread: Re: Giving several functions the same argument