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

• To: mathgroup at smc.vnet.net
• Subject: [mg65925] Re: How to extract functions from a list and call them with any argument?
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Mon, 24 Apr 2006 06:01:16 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <e2fkto\$bp7\$1@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:=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
>
You can either use replacement rules (In, In) or define your
functions as pure functions (In). For instance

In:=
funclist = {Sin[x], x^3, Cos[x]^2};

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

Out=
Sin[t]

In:=
funclist[] /. x -> 3

Out=
27

In:=
funclist2 = {Sin[#1] & , #1^3 & , Cos[#1]^2 & };

In:=
funclist2[][t]

Out=
Sin[t]

In:=
funclist2[]

Out=
27

Best regards,
Jean-Marc

```

• Prev by Date: Re: matrix operations -- shared data vs copied
• Next by Date: Re: How to extract functions from a list and call them with any argument?
• 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?