       Re: Function argument

• To: mathgroup at smc.vnet.net
• Subject: [mg66992] Re: Function argument
• Date: Tue, 6 Jun 2006 06:28:07 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 6/5/06 at 3:47 AM, Banerjee at cse.ohio-state.edu (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.

Note in Mathematica ax is distinctly different from a x or a*x. So, unless g is written in an unusual way, g[1,ax^2+bx+c] will not evaluate to a+b+c

But it is quite easy to create a function that will return what you want given the arguments 1 and a*x^2+b*x+c. For example,

In:=
g[a_, f_] := f /. x -> a

In:=
g[1,a x^2+b x+c]

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

In:=
g[Pi,Sin[x]]

Out=
0

Note, the definition I've used for g assumes x as the independent variable. Also, I wonder why you want such a function since it as easy (if not easier) to write

In:=
a x^2 + b x + c /. x -> 1

Out=
a+b+c