Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 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: [mg65943] Re: How to extract functions from a list and call them with any argument?
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Mon, 24 Apr 2006 06:01:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 4/23/06 at 6:17 AM, 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].

One way to do what you want would be to use pure functions when you set up funclist, i.e.,

funclist = {Sin@# &, #^3 &, Cos[#]^2 &};

then you can do

In[2]:=
funclist[[1]][x]

Out[2]=
Sin[x]
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: solving a set of inequalities
  • Next by Date: Re: matrix operations -- shared data vs copied
  • Previous by thread: Re: 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?