I'm struggling with the following problem. It is necessary to find the derivative expression with respect to the vector $u$:
$r(u,v)=[(u-v)(u-v)^T]\begin{pmatrix} 1\\ 1\\ 1 \end{pmatrix}=[(u-v)\otimes (u-v)]\begin{pmatrix} 1\\ 1\\ 1 \end{pmatrix}$
If we use the results from the topic Derivative of Kronecker product of vector with itself, we get:
$\frac{dr}{du}=[(\big(I\otimes(v-u)\big) + \big((v-u) \otimes I\big))]\begin{pmatrix} 1\\ 1\\ 1 \end{pmatrix}$
When I try to figure out the bracketed expression using Mathematica, I get an error. As far as I understand, something is wrong in the original formula, because the summed arrays have different dimensions.
I need help from more experienced professionals. I would be glad and grateful for help.
Clear["Derivative"]
ClearAll["Global`*"]
u = {a, b, c};
v = {x, y, z};
KroneckerProduct[u - v, u - v] // MatrixForm;
(KroneckerProduct[DiagonalMatrix[{1, 1, 1}], v - u] +
TensorProduct[v - u, DiagonalMatrix[{1, 1, 1}]]) // MatrixForm
$ \def\v{\operatorname{vec}} \def\o{{\tt1}} \def\p{{\partial}} \def\grad#1#2{\frac{\p #1}{\p #2}} $There's no need for Kronecker products, just define the vector $$\eqalign{ w &= u-v \qquad\qquad\quad \\ dw &= du \\ }$$ Write the function in terms of this new variable $$r = ww^T\o = w\o^Tw \quad $$ Then calculate the differential and its gradient $$\eqalign{ dr &= dw\;\o^Tw + w\o^T\,dw \\ &= \Big(\!\left(\o^Tw\right)I+ w\o^T\Big)\,dw \\ &= \Big(\!\left(\o^Tw\right)I+ w\o^T\Big)\,du \\ \grad{r}{u} &= \left(\o^Tw\right)I+ w\o^T \\ \\ }$$
If instead, you really did want the gradient of the scalar function $$\eqalign{ \phi &= (w\otimes w)^T\o \\ }$$ Then let $J$ denote the all-ones matrix $$\eqalign{ \phi &= (w\otimes w)^T\v(J) \\ &= \v(w^TJw) \\ &= w^TJw \\ \grad{\phi}{w} &= 2Jw \;\doteq\; \grad{\phi}{u} \\ }$$