On 8/5/08 at 3:59 AM, eitan at grinspun.com (Eitan Grinspun) wrote:
>I would like to compute the gradient F' of a scalar-valued function
>F of a vector-valued argument, without knowing a-priori the
>dimensions of the vector.
>I am having some trouble with a very simple case.
>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.
Expected yes given the way the form F' works, but reasonable? A
dot product of vector and any other vector is a scalar. If you
give specific values for the vector components, I would think it
would be reasonable to return a value zero. Further, the
gradient of a vector isn't given by the derivative of the dot
product. Instead, it is the sum of partial derivatives of each
component with respect to the corresponding basis function. That
is the gradient of vector {x, y w, z^2} is given by
In[27]:= Tr@D[{x, y w, z^2}, {{x, y, z}}]
Out[27]= w+2 z+1