Re: Turning Derivative into Function (Newbie Question)

*To*: mathgroup at smc.vnet.net*Subject*: [mg115462] Re: Turning Derivative into Function (Newbie Question)*From*: Just A Stranger <forpeopleidontknow at gmail.com>*Date*: Tue, 11 Jan 2011 19:22:07 -0500 (EST)

Thanks guys! That pure function approach looks the most concise...that would be the best approach with regards to Mathematica's design philosophy? I'll sink my teeth into the documentation. :) On Tue, Jan 11, 2011 at 7:10 AM, Murray Eisenberg <murray at math.umass.edu>wrote: > Because g is NOT a "function" when you set: > > g := f'[x] > > (No more than f would be had you started with f := x^2.) > > Whenever you now call g, you get the value of f[x], namely, 2x. > > If you really want to define g that way, then you can use a rule and > replacement: > > g /. x-> 2 > > But it's probably better to do things like this: > > Clear[g] > g[x_] = f'[x] (* note Set, =, not SetDelayed, := *) > g[2] > 4 > > Or, if you prefer a more functional approach: > > Clear[g] > g = f' > g[2] > 4 > > > On 1/11/2011 6:58 AM, Just A Stranger wrote: > >> When I apply a function that outputs another function, how come I can not >> pass arguments to the new function? Am I missing some principle about how >> Mathematica functions work? Could someone please point me to the relevant >> documentation? >> >> >> A simple example to illustrate my confusion: >> >> In[1]: f[x_] := x^2 >> In[2]: g := f'[x] >> >> So now I have: >> >> In[3]: g >> out[3]: 2x >> >> as expected >> >> So how come I get the following when trying to pass an argument to g: >> >> In[4]: g[2] >> Out[4]: 2x[2] >> >> Instead of the output I want: >> >> *Ou[4]: 4 >> >> >> I tried >> >> In: g[x_] := f'[x] >> >> But it seems to think I'm trying to assign a function to Times. >> "SetDelayed::write: Tag Times in (2 x)[y_] is Protected.>>" >> >> Thank you very much for any help :) >> >> >> > -- > Murray Eisenberg murray at math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street fax 413 545-1801 > Amherst, MA 01003-9305 >