Re: Re: Derivative of Dot[]

*To*: mathgroup at smc.vnet.net*Subject*: [mg91133] Re: [mg91085] Re: Derivative of Dot[]*From*: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>*Date*: Thu, 7 Aug 2008 04:38:54 -0400 (EDT)*References*: <g791cq$9hc$1@smc.vnet.net> <200808060902.FAA22060@smc.vnet.net>

On Wed, Aug 6, 2008 at 2:35 PM, Eitan Grinspun <eitan at grinspun.com> wrote: >>> Consider the following function: >>> >>> F[x_] := Dot[x,x] >>> >>> Evaluating this function works as expected: F[{1,2}] evaluates to 5. >>> >>> I differentiate this function w.r.t. its sole argument, F' evaluates >>> to 1.#1+#1.1& >>> >>> This is reasonable, and as expected. I would think that, since the >> >> The above expression make sense only for one dimensional vectors, say on >> the real line; in other words, a vector space where the unit vector is >> {1} and any vector {x} has only one component x. > > Why? Even of a vector {x}, the resulting derivative cannot be > evaluated successfully: (1.#1+#1.1&)[{x}] does not simplify (the 1. > remains). Oops! You are right, of course. (I was too fast to answer did not spot that the dot was for the dot product and not associated with the ones (1.) as floating-point numbers (and so there was no implicit multiplication)! Sorry for any confusion. >> You may want to write you own differentiating function such as the >> following: Note that I missed the point that you wanted to compute the gradient. As pointed out by Bill Rowe, the derivative of the dot product is not the gradient. So beware that the function I gave you in example differentiates a dot product but does not compute the gradient. > I have done so before; but the question is what is the intended use of > the built in derivative of Dot? I can't find one. I believe that Andrzej Kozlowski's replies (note that there are two of them) clearly explain how the derivative of the dot product is derived the way it is, as well as the rational behind it. Be sure to read both of them if you have not done so yet. Regards, - Jean-Marc > Eitan > >> >> In[1]:= >> SetAttributes[myDiff, HoldFirst] >> myDiff[fun_[x_?VectorQ]] := >> Module[{v = Array[a, Length[x]]}, >> D[fun[v], {v}] /. Thread[v -> x]] >> >> f[x_?VectorQ] := Dot[x, x] >> myDiff[f[{1, 2}]] >> myDiff[f[{1, 2}]].{3, 4} >> >> g[y_] := 2 f[y] >> myDiff[g[{1, 2}]] >> myDiff[g[{1, 2}]].{3, 4} >> >> Out[4]= {2, 4} >> >> Out[5]= 22 >> >> Out[7]= {4, 8} >> >> Out[8]= 44

**References**:**Re: Derivative of Dot[]***From:*Jean-Marc Gulliet <jeanmarc.gulliet@gmail.com>