       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:=
g[a_, f_] := f[a]

You can test it with different types of expressions:

In:=
g[0, Sin]

Out=
0

In:=
g[0, Cos]

Out=
1

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

In:=
g[3, h]

Out=
9

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

Out=
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