MathGroup Archive 2007

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

Search the Archive

Re: Differentiation and evaluation of function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75054] Re: [mg75041] Differentiation and evaluation of function
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 16 Apr 2007 04:04:51 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

f[x_]:=3x^2;

Use Set instead of SetDelayed to define y

Clear[y];
y[x_]=D[f[x],x];

{f[3],y[x],y[3]}

{27,6 x,18}

Or you can force SetDelayed to work by using a dummy variable

Clear[y];
y[x_]:=D[f[t],t]/.t->x;

{f[3],y[x],y[3]}

{27,6 x,18}


Bob Hanlon

---- "Apostolos E. A. S. Evangelopoulos" <a.e.a.evangelopoulos at sms.ed.ac.uk> wrote: 
> In spite of this problem's apparent simplicity, I cannot find an answer to what goes wrong:
> I begin by declaring a function f[x_] and defining its derivative function y[x_], then ask for an evaluation of 'y' for two simple arguments, one being the variable 'x,' the other a number. Evaluation of y['number'] is impossible and implies that there is something inherently different about the functions 'f' and 'y,' since f['number'] is not a problem, while y['number'] is! My inputs/outputs, in particular, are the following:
> 
> In[1]:= f[x_]:=3 x^2
> In[2]:= ?f
>         Global`f
>         f[x_]:=3 x^2
> In[3]:= y[x_]:= D[f[x], x]
> In[4]:= ?y
>         Global`y
>         y[x_]:='partial d sub[x]' f[x]
> In[5]:= f[3]
> Out[5]:= 27
> In[6]:= y[x]
> Out[6]:= 6 x
> In[7]:= y[3]
>         General::ivar : 3 is not a valid variable
> 
> Everything above seems reasonable with the exception of the last input. This feels even more confusing if one thinks that the general method has worked for me, yet with much more complicated functions, for which Mathematica has no problem perfoming both symbolic and numerical evaluations!
> 
> I hope someone can enlighten this mystery!
> 
> Many thanks,
> Apostolos
> 



  • Prev by Date: LegendreP Evaluation Mystery
  • Next by Date: what does this error message mean
  • Previous by thread: Differentiation and evaluation of function
  • Next by thread: Re: Differentiation and evaluation of function