Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Function argument

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66992] Re: Function argument
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • 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[1]:=
g[a_, f_] := f /. x -> a

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

Out[2]=
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[3]:=
g[Pi,Sin[x]]

Out[3]=
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[4]:=
a x^2 + b x + c /. x -> 1

Out[4]=
a+b+c

instead of g[1,a x^2+b x+c]
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Re: Colored Tick Labels?
  • Next by Date: RE: Animate
  • Previous by thread: Re: Function argument
  • Next by thread: RE: Function argument