MathGroup Archive 2006

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

Search the Archive

Re: Function argument

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66972] Re: [mg66953] Function argument
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 6 Jun 2006 06:26:53 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

g[a_,func_, x_Symbol:x] := func/.x->a;

g[a,f[x]]

f(a)

g[a,f[y],y]

f(a)

g[1,a*x^2+b*x+c]

a+b+c

g[1,a*z^2+b*z+c,z]

a+b+c

g[Pi,Sin[x]]

0

or just use Function

Function[x,f[x]][a]

f(a)

f[#]&[a]

f(a)

Function[x,a*x^2+b*x+c][1]

a+b+c

a#^2+b#+c&[1]

a+b+c

Function[x,Sin[x]][Pi]

0

Sin[#]&[Pi]

0


Bob Hanlon

---- Bonny <Banerjee at cse.ohio-state.edu> 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. 
> 
> 

--

Bob Hanlon
hanlonr at cox.net



  • Prev by Date: Re: Function argument
  • Next by Date: Re: Re: schur decomposition and mathematica
  • Previous by thread: Re: Function argument
  • Next by thread: Re: Function argument