Derivative of $\operatorname{trace}(XWW^{T}X^{T})$ with respect to $W$ Compute
$$\frac{d}{dW}\operatorname{trace}(XWW^T X^T)$$
where $X$, $W$ are $n\times n$ real matrices.

Let $f : \mathbb R^{n \times n} \to \mathbb R$ be defined by
$$f (\mathrm X) = \mbox{tr} (\mathrm A \mathrm X \mathrm X^T \mathrm A^T)$$
The directional derivative of $f$ in the direction of $\mathrm V$ at $\mathrm X$ is
$$\begin{array}{rl} D_{\mathrm V} f (\mathrm X) &= \mbox{tr} (\mathrm A \mathrm V \mathrm X^T \mathrm A^T) + \mbox{tr} (\mathrm A \mathrm X \mathrm V^T \mathrm A^T)\\ &= \mbox{tr} (\mathrm X^T \mathrm A^T \mathrm A \mathrm V) + \mbox{tr} (\mathrm V^T \mathrm A^T \mathrm A \mathrm X)\\ &= \mbox{tr} ((\mathrm A^T \mathrm A \mathrm X)^T \mathrm V) + \mbox{tr} (\mathrm V^T \mathrm A^T \mathrm A \mathrm X)\\ &= \langle \mathrm A^T \mathrm A \mathrm X, \mathrm V \rangle + \langle \mathrm V, \mathrm A^T \mathrm A \mathrm X \rangle\\ &= \langle 2 \mathrm A^T \mathrm A \mathrm X, \mathrm V \rangle\end{array}$$
Hence,
$$\nabla f (\mathrm X) = 2 \mathrm A^T \mathrm A \mathrm X$$

matrix-calculus scalar-fields gradient
