# Derivative of trace of matrix product including inverse

Let $A,B,X$ be n-by-n matrices, $X$ is nonsingular so $X^{-1}$ exist.

What will $\frac{\partial Tr(XAX^{-1}B)} {\partial X}$ be?

-

From Wikipedia or the matrix cookbook, we have

$$\def\Tr{\operatorname{Tr}} \frac{\partial \Tr\left(X^{-1}M\right)}{\partial X}=-\left(X^{-1}MX^{-1}\right)^\top\;,$$

so

$$\frac{\partial\Tr\left(XAX^{-1}B\right)}{\partial X}=\frac{\partial\Tr\left(X^{-1}BXA\right)}{\partial X}=\left(AX^{-1}B\right)^\top-\left(X^{-1}BXAX^{-1}\right)^\top\;.$$

Note that at $X=I$ this is the transpose of the commutator $AB-BA$.

-
Could you elaborate more on how you do matrix derivative of Trace? I have read the matrix cookbook but I don't really get what "scalar derivative" means. Thank you! – Rein Mar 6 '13 at 12:31
One more question, if the matrix $Q$ is othogonal, i.e. $Q^T=Q^{-1}$, from matrix cookbook we have $\frac{\partial Q^TBQA}{\partial Q} = BQA+B^TQA^T$. Yet by plugging $Q^T$ into $Q^{-1}$ we cant yield the same formulation. Is there any problem on directly plugging $Q^T$ into $Q^{-1}$? – Rein Mar 6 '13 at 12:51
Correction: Should be $\frac {\partial Tr(Q^TBQA)} {\partial Q}$ – Rein Mar 6 '13 at 13:53