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: [mg67001] Re: [mg66953] Function argument
  • From: "Bharat Bhole" <bbhole at gmail.com>
  • Date: Tue, 6 Jun 2006 06:28:58 -0400 (EDT)
  • References: <200606050747.DAA16312@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bonny,

One way this can be done is (which I think you already know)
f1[x_] := ax^2+bx+c
f2[x_]:=Sin[x]
g[a_,f_]:=f[a]

Then,
g[1,f1]=a+b+c
g[pi,f2]=0

Another way is the following. Does not seem the best way, but will work as
long as your function f(.) is always in terms of the same variable, say *x.*
Define,

g[a_,b_]:=b /. x->a

Then,
g[1,ax^2+bx+c] =a+b+c
g[pi,Sin[x]] = 0

Best,
Bharat.






On 6/5/06, 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.
>
>
>

------=_Part_5942_27787247.1149522588839

<div>Bonny,</div>
<div>&nbsp;</div>
<div>One way this can be done is (which I think you already know)</div>
<div>f1[x_] := ax^2+bx+c</div>
<div>f2[x_]:=Sin[x]</div>
<div>g[a_,f_]:=f[a]</div>
<div>&nbsp;</div>
<div>Then,</div>
<div>g[1,f1]=a+b+c</div>
<div>g[pi,f2]=0</div>
<div>&nbsp;</div>
<div>Another way is the following. Does not seem the best way, but will work as long as your function f(.) is always in terms of the same variable, say <em>x.</em></div>
<div>Define,</div>
<div>&nbsp;</div>
<div>g[a_,b_]:=b /. x-&gt;a</div>
<div>&nbsp;</div>
<div>Then, </div>
<div>g[1,ax^2+bx+c] =a+b+c</div>
<div>g[pi,Sin[x]] = 0</div>
<div>&nbsp;</div>
<div>Best,</div>
<div>Bharat.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><br><br>&nbsp;</div>
<div><span class="gmail_quote">On 6/5/06, <b class="gmail_sendername">Bonny</b> &lt;<a href="mailto:Banerjee at cse.ohio-state.edu">Banerjee at cse.ohio-state.edu</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">I would like to define a function g that evaluates another function f at a<br>given value. That is,<br><br>
g[a, f[x]] := f[a]<br><br>For example, I might want the function f[x]=ax^2+bx+c to be evaluated at x=1<br>and get the result a+b+c. That is,<br><br>g[1, ax^2+bx+c] should evaluate to a+b+c.<br><br>Again, I might want the function f[x]=Sin[x] to be evaluated at x=pi and get
<br>the result 0. That is,<br><br>g[pi, Sin[x]] should evaluate to 0.<br><br>Is there a way to accomplish this in Mathematica? Any help would be<br>appreciated.<br><br>Thanks,<br>Bonny.<br><br><br></blockquote></div><br>

------=_Part_5942_27787247.1149522588839--


  • Prev by Date: RE: Packages--guikit and mathgl3d help!
  • Next by Date: Re: piecewise integration
  • Previous by thread: Function argument
  • Next by thread: Re: Function argument