I've came across the following function
$$f(X) := \mbox{tr} \left( \left( X^T X - A \right)^T \left(X^T X - A \right) \right)$$
where $A$ is a given matrix. I need help taking the derivative of this function w.r.t $X$. I.e, what is $\partial f(X) / \partial X ?$
The Frobenius product can be used to write the function and its differential as $$ \eqalign { f &= \|M\|^2_F = M:M \cr\cr df &= 2\,M:dM \cr &= 2\,(X^TX-A):(dX^TX+X^TdX) \cr &= 2\,(X^TX-A):2\,\,{\rm sym}(X^TdX) \cr &= 2\,\,{\rm sym}(X^TX-A):2\,(X^TdX) \cr &= (2\,X^TX - A-A^T):2\,(X^TdX) \cr &= (4\,XX^TX - 2\,XA - 2\,XA^T):dX \cr } $$ Since $df=\big(\frac {\partial f} {\partial X}:dX\big)\,$ the derivative must be $$ \frac {\partial f} {\partial X} = 4\,XX^TX - 2\,XA - 2\,XA^T $$