MathGroup Archive 2007

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

Search the Archive

Re: Applying a list of functions to a single number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74548] Re: Applying a list of functions to a single number
  • From: "dimitris" <dimmechan at yahoo.com>
  • Date: Sun, 25 Mar 2007 01:29:34 -0500 (EST)
  • References: <eu1peu$eu1$1@smc.vnet.net>

In[13]:=
square[x_] := x^2
cube[x_] := x^3

In[15]:=
Through[{square, cube}[5]]
Out[15]=
{25,125}

In[16]:=
({square[#1], cube[#1]} & )[5]
Out[16]=
{25,125}

In[17]:=
(#1[5] & ) /@ {square, cube}
Out[17]=
{25,125}

In[18]:=
{square[5], cube[5]}
Out[18]=
{25,125}

In[19]:=
{square, cube, 5} /. {x_, y_, z_} :> {x[z], y[z]}
Out[19]=
{25,125}

In[20]:=
Flatten[({square[#1], cube[#1]} & ) /@ {5}]
Out[20]=
{25, 125}

In[22]:=
Information[Through]
>From In[22]:=
"Through[p[f1, f2][x]] gives p[f1[x], f2[x]]. Through[expr, h]
performs the transformation wherever h
occurs in the head of expr."
>From In[22]:=
Attributes[Through] = {Protected}

Regards
Dimitris

=CF/=C7 siewsk at bp.com =DD=E3=F1=E1=F8=E5:
> Applying a list of functions to a single number
> =========================
=========
>
> I have
>
> Square[x_]:=x^2
> Cube[x_]:=x^3
>
> I have tried
>
> In[2]:={Square,Cube} @ 5
>
> Out[2]:= {Square,Cube}[5]
>
> But what I wanted is a list containing
>
>  {25,125}
>
> Obviously I'm doing this the wrong way. What is the correct way?



  • Prev by Date: Re: including part of files ?
  • Next by Date: Re: simplifications
  • Previous by thread: Re: Applying a list of functions to a single number
  • Next by thread: Inverse of arbitrary functions