MathGroup Archive 2006

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

Search the Archive

Re: Function argument

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66971] Re: Function argument
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 6 Jun 2006 06:26:52 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <e60o3q$g5s$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bonny wrote:
> I would like to define a function g that evaluates another function f at a 
> given value. That is,
> 
> g[a, f[x]] := f[a]
> 
> For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1 
> and get the result a+b+c. That is,
> 
> g[1, ax^2+bx+c] should evaluate to a+b+c.
> 
> Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get 
> the result 0. That is,
> 
> g[pi, Sin[x]] should evaluate to 0.
> 
> Is there a way to accomplish this in Mathematica? Any help would be 
> appreciated.
> 
> Thanks,
> Bonny. 
> 
> 

Hi Bonny,

What about the following definition for the function g:

In[1]:=
g[a_, f_] := f[a]

You can test it with different types of expressions:

In[2]:=
g[0, Sin]

Out[2]=
0

In[3]:=
g[0, Cos]

Out[3]=
1

In[4]:=
h[x_] := x^2

In[5]:=
g[3, h]

Out[5]=
9

In[6]:=
g[1/2, 1/#1 & ]

Out[6]=
2

HTH,
Jean-Marc


  • Prev by Date: RE: Function argument
  • Next by Date: Re: Function argument
  • Previous by thread: RE: Function argument
  • Next by thread: Re: Function argument