MathGroup Archive 2006

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

Search the Archive

Re: How to extract functions from a list and call them with any argument?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65927] Re: [mg65919] How to extract functions from a list and call them with any argument?
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Mon, 24 Apr 2006 06:01:18 -0400 (EDT)
  • References: <200604231017.GAA11838@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

dmp55 at sympatico.ca wrote:
> I have a list of functions, i.e.,
> 
> funclist = {Sin[x], x^3, Cos[x]^2}.
> 
> I can extract each of the functions, like
> 
> In[1]:=funclist[[1]]
> Out[1]=Sin[x]
> 
> , but I don't know how to call these functions with a general argument.
> If I type
> 
> In[2]:=funclist[t][[1]]
> 
> , I get
> 
> Out[2]=t
> 
> instead of Sin[t] (or t^3 or Cos[t]^2)
> 
> What I would like is to extract a function from the list and to call it
> with any argument, as it was defined in a standard way:
> f[x_]:=Sin[x].
> 
> Dom

Sounds like you want to convert the functions in the list to pure 
functions. Here is a method to do so:

In[1]:= f3 = Function[{x}, #]&[ funclist[[3]] ]

Out[1]= Function[{x}, (Cos[x])^2]

Lets see if it works:

In[2]:= f3[3]

Out[2]= (Cos[3])^2

Carl Woll
Wolfram Research


  • Prev by Date: Re: How to remove extra empty lines generated when exporting to HTML?
  • Next by Date: Width of plots
  • Previous by thread: How to extract functions from a list and call them with any argument?
  • Next by thread: Re: How to extract functions from a list and call them with any argument?