Let $A$ be a $N\times5$ matrix, $\vec{b}$ be an $N \times 1$ vector and $\vec{x}$ be a $5\times1$ vector. I am looking for the derivative of the function,
$$f(\vec{x}) = \text{Trace}((A\vec{x}\vec{x}^TA^T - \vec{b}\vec{b}^T)\circ(A\vec{x}\vec{x}^TA^T - \vec{b}\vec{b}^T))$$
where $\circ$ denotes the Hadamard product.
I have checked some of the answered questions in the forum and try to derive for the solution myself but I am not sure if I derive the term correctly. What I get in the end has a sensible dimension. Can you check whether the term is correct? Or I miss anything?
$$\frac{\partial f}{\partial\vec{x}} = 4(A\vec{x}\vec{x}^TA^T - \vec{b}\vec{b}^T)A\vec{x}$$
Thank you.
Your answer is very close -- just diagonalize the term in parentheses and pre-multiply by $A^T$.
Here are the details.
For typing convenience, define the symmetric matrix $$\eqalign{ M &= Axx^TA^T-bb^T \\ }$$ Write the function in terms of this variable, then calculate its differential and gradient. $$\eqalign{ f &= (I\odot I):(M\odot M) \\ &= (I\odot M):(I\odot M) \\ df &= 2(I\odot M):(I\odot dM) \\ &= 2(I\odot M):dM \\ &= 2(I\odot M):A\,d(xx^T)\,A^T \\ &= 2A^T(I\odot M)A:d(xx^T) \\ &= 2A^T(I\odot M)A:2\operatorname{Sym}(dx\,x^T) \\ &= 4\operatorname{Sym}\big(A^T(I\odot M)A\big):(dx\,x^T) \\ &= 4\,A^T(I\odot M)Ax:dx \\ \frac{\partial f}{\partial x} &= 4\,A^T(I\odot M)Ax \\ }$$ $$\eqalign{ }$$ where $I$ is the identity matrix, $\odot$ is denotes the elementwise/Hadamard product, a colon denotes the trace/Frobenius product, i.e. $$A:B = \operatorname{Tr}(A^TB)$$ and Sym() is the symmetrization operator $$\operatorname{Sym}(A) = \frac{A+A^T}{2}$$ At the risk of introducing yet another function, one might also write $$I\odot M = \operatorname{Diag}(M)$$