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

• To: mathgroup at smc.vnet.net
• Subject: [mg65928] Re: [mg65919] How to extract functions from a list and call them with any argument?
• From: "Szabolcs Horvát" <szhorvat at gmail.com>
• Date: Mon, 24 Apr 2006 06:01:21 -0400 (EDT)
• References: <200604231017.GAA11838@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On 4/23/06, dmp55 at sympatico.ca <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:=funclist[]
> Out=Sin[x]
>
> , but I don't know how to call these functions with a general argument.
> If I type
>
> In:=funclist[t][]
>
> , I get
>
> Out=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
>
>

First I'd like to note that those, in you list are not functions, but
expressions. If you's like to make a list of functions, you could use
the following syntax:

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

Here # stands for the argument of the function and you must append the
"&" sign to the function definition. Note that you may use Sin instead
of Sin[#]&

In:= funclist[][t]

Out= Sin[t]

In:= funclist[][t]

Out= t^3

Look up "Pure functions" in the Master Index of the Mathematica help browser.

For your problem it may be a better solution to Replace[ ] x in the expressions:

exprlist = {Sin[x], x^3, Cos[x]^2}

In:= exprlist[] /. x -> t

Out= Sin[t]

For example Cos[x]^2 /. x -> t replaces every occurrence of x in the
left side of /. by t. Look up ReplaceAll[ ] in the help broswer.

Szabolcs HorvÃ¡t

```

• Prev by Date: Re: matrix operations -- shared data vs copied
• Next by Date: Re: unable to FullSimplify
• 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?