What is the gradient of the trace of an outer-product? [closed]

How can we find: $$\frac{\partial}{\partial\mathbf{x}}\operatorname{tr}(\mathbf{xx}^{T})=\;?$$ Now from the matrix cookbook, I found that: $$\frac{\partial}{\partial\mathbf{X}}\operatorname{tr}(\mathbf{X})=\mathbf{I}$$ but in my case, I am deriving with respect to a vector.

• en.wikipedia.org/wiki/Matrix_calculus#Scalar-by-vector tells you how to interpret the derivative. Sep 30, 2022 at 7:19
• I suspect that $\mathbf x = (x_1,\ldots,x_n)^T$ is a column vector. Then $\operatorname{tr}(\mathbf x \mathbf x^T) = x_1^2 + \ldots + x_n^2$. You have not used enough words (or notation) to explain why you want this. Oct 8, 2022 at 1:51

Since $$tr(xx^T) = x^Tx$$, the derivative is simply $$2x$$ (or $$2x^T$$ if you are interpreting the gradient as a row vector).
• A small remark: $trace(xx^T) = x^Tx$ is a particular case of a more general property, valid for any matrices $A \ (n \times p)$ and $B \ (p \times n)$ : $trace(AB)=trace(BA)$ Sep 30, 2022 at 8:53
• @Arthur I agree that there's a case to be made for row vector gradients, but it is certainly not universally written that way. For example the gradient operator $\nabla$ is sometimes interpreted as a row vector itself (for the reasons you mentioned) so that the divergence of a column vector field $\vec u$ is $\nabla\cdot \vec u$. But that would mean vector fields like $\nabla p$ for a scalar field $p$ need to be interpreted themselves as column vectors in order to operations like this to make sense. There is some discussion of the nuances here: en.wikipedia.org/wiki/Gradient#Derivative Oct 1, 2022 at 20:39