Re: How to extract functions from a list and call them with any argument?
- To: mathgroup at smc.vnet.net
- Subject: [mg65957] Re: How to extract functions from a list and call them with any argument?
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Mon, 24 Apr 2006 06:02:19 -0400 (EDT)
- 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[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 > The short answer is that you don't have a list of functions - you have a list of expressions, so you need to replace x by whatever you want: funclist[[1]]/. x->t However, this is not an ideal way to work because if x gets a value somewhere else, that value will get substituted before you can get the desired replacement. It would probably be better to use a real list of functions - pure functions - looking like: {Sin,#^3&,Cos[#]^2&} Your question indicates that you are probably a beginner with Mathematica, and it would really help to read that big book a bit and try the examples. After a while, you will find that the right way to do things gradually soaks in! David Bailey http://www.dbaileyconsultancy.co.uk