Re: Incoherent value for partial derivative
- To: mathgroup at smc.vnet.net
- Subject: [mg91075] Re: Incoherent value for partial derivative
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Tue, 5 Aug 2008 04:03:44 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g76auv$dks$1@smc.vnet.net>
Miguel wrote: > Let > > In[1]: g[x_]:=3x^2+5x; > FullForm[g'[x]] > > Out[1]: Plus[5,Times[6,x]] > > In[2]: g'[2] > Out[2]: 17 > > Mathematica works fine and the result is correct. First, it executes > the derivation and then the delayed substitution/assignation. This is true only for the *special* form g'[2]. If you use D[g[2],x], you get similar result and behavior as for D[f[1,2],x]. The operator D always evaluates its arguments in the same and consistent way, regardless of the name and number of variables. However, the ' (prime) form is a special form that does *not* evaluate its argument as the operator D does. (And prime works only for a function of one variable.) In other words, the ' (prime) form and the operator D form are *not* equivalent and they are not interchangeable without care. In[1]:= g[x_] := 3 x^2 + 5 x; g'[2] // Trace D[g[2], x] // Trace Out[2]= 2 2 {{g', {g[#1], 3 #1 + 5 #1, 5 #1 + 3 #1 }, 5 + 6 #1 & }, (5 + 6 #1 & )[2], 5 + 6 2, {6 2, 12}, 5 + 12, 17} Out[3]= 2 2 {{g[2], 3 2 + 5 2, {{2 , 4}, 3 4, 12}, {5 2, 10}, 12 + 10, 22}, D[22, x], 0} As we can see above, the ' (prime) form first the function into an pure function and takes its first derivative, then applies the resulting pure function to the numeric value (2) passed as argument of the original function. On the other hand, the operator D first evaluates its argument, which yields a numeric value, i.e. a constant, and since the derivative of a constant with respect to whatever variable is zero, the result is zero. > But for > partial derivative Mathematica works different way (not correspondig > to FullForm FullForm is irrelevant here: what matters is when the arguments are evaluated and how they are transformed before before applying numeric value. Trace is more appropriate to visualize what is going on. You can see the the reasoning (and behavior) is similar to what we did above. In[4]:= f[x_, y_] := x^2 + x y^2; FullForm[D [f[x, y], x]] D[f[1, 2], x] // Trace Out[5]//FullForm= Plus[Times[2, x], Power[y, 2]] Out[6]= 2 2 2 2 {{f[1, 2], 1 + 1 2 , {1 , 1}, {{2 , 4}, 1 4, 4}, 1 + 4, 5}, D[5, x], 0} > In[3]: f[x_,y_]:=x^2+x y^2; > FullForm[\!\( > \*SubscriptBox[\(\[PartialD]\), \(x\)]\ \(f[x, y]\)\)] > > Out[3]: Plus[Times[2,x],Power[y,2]] > > In[4]: \!\( > \*SubscriptBox[\(\[PartialD]\), \(x\)]\ \(f[1, 2]\)\) > Out[4]: 0 > > I dont understand the reason. Hope this helps, -- Jean-Marc