0
$\begingroup$

Set a matrix $X\in \mathbb{R}^{n\times n}$ and a symmrtric matrix $A\in\mathbb{R}^{n\times n}$. I'm trying to get $\frac{\partial\text{tr}\left(XAX\right)}{\partial X}$. If the matrix $X$ is asymmetric, I have that $\frac{\partial\text{tr}\left(XAX\right)}{\partial X}=X^\top A+AX^\top$; If the matrix $X$ is symmetric, I have that $\frac{\partial\text{tr}\left(XAX\right)}{\partial X}=2\left(XA+AX\right)$. But the matrixcalculus gives me a quite strange answer when $X$ is symmetric: $$ \frac{\partial\text{tr}\left(XAX\right)}{\partial X}=\frac{1}{2}\left(\left(T_0+T_1\right)^\top +T_0+T_1\right) $$ where $T_0 =XA$ and $T_1 =AX$.

I want to know how to get this result.

$\endgroup$
1
  • $\begingroup$ This is a special case of the duplicate. Here, where $X$ is symmetric, $XAX=XAX^\prime$ translates to $ABA^\prime C$ with $X$ corresponding to $A$, $A$ corresponding to $B,$ and $C$ the identity matrix. For (many) more related questions, please search our site for matrix derivative. $\endgroup$
    – whuber
    Commented Sep 9 at 13:50

2 Answers 2

1
$\begingroup$

I'm not sure where you got your solution from - specifically, the $2$ in front. If you ignore that $X$ is symmetric and use the your first expression, your expression for the symmetric case is twice as large. From the cookbook, equation 114:

$$ \frac{\partial}{\partial X} Tr(AXBX) = A^\top X^\top B^\top + B^\top X^\top A^\top $$ so with $A=I$ (and $B=A$ from your problem) this simplifies to $X^\top A^\top + A^\top X^\top = XA + AX$, half your expression.

I think you worked this out already, but $(t_0 + t_1)^\top = (XA)^\top + (AX)^\top = A^\top X^\top + X^\top A^\top = AX + XA$, and the matrixcalculus result simplifies to $AX + XA$.

$\endgroup$
1
$\begingroup$

I find a general result (for not necessarily square or symmetric matrices) as

$$\frac{\partial\text{tr}\left(XAX^\top C\right)}{\partial X}= AXC + A^\top X C^\top.$$

A quick proof can be found here,

https://web.stanford.edu/~jduchi/projects/matrix_prop.pdf

With $C = I_n$, we get

$$\frac{\partial\text{tr}\left(XAX^\top \right)}{\partial X}= AX + A^\top X.$$

For square and symmetric matrices

$$\frac{\partial\text{tr}\left(XAX^\top \right)}{\partial X}= \frac{\partial\text{tr}\left(XAX \right)}{\partial X} = AX + AX = 2AX.$$

$\endgroup$
2
  • $\begingroup$ But the result I get is twice the result given by matrixcalculus $\endgroup$
    – mathhahaha
    Commented Aug 27 at 13:22
  • $\begingroup$ @mathhahaha Silly (me). Didn't even notice the $(1/2)$. I re-worked my answer. $\endgroup$ Commented Aug 27 at 18:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.