[Math] Derivative of a function involving diagonal matrix

derivativeslinear algebramatricesmatrix-calculusmultivariable-calculus

Let $A$ be a $n\times n$ matrix, $\text{diag}(x)$ is the diagonal matrix with $x$ on the diagonal. How can I find $dF(x)$ for $F(x) = \text{diag}(x)Ax$?

Thank you very much in advance!

Best Answer

$ \def\d#1{\operatorname{Diag}\left(#1\right)} $If you use the Hadamard (aka elementwise) product, then you can get rid of the diag operation, which will make it easier to find the differential and jacobian of the function. $$\eqalign{ f &= x\circ(Ax) \\ &= \d{Ax}\,x \;=\; \d{x}\,Ax \\ df &= \d{Ax}\,dx + \d{x}\,A\,dx \\ &= \Big(\d{Ax} + \d{x}\,A\Big)\,dx \\ \frac{\partial f}{\partial x} &= \d{Ax} + \d{x}\,A \\\\ }$$ Special properties of the Hadamard product were used in several steps, i.e. $$\eqalign{ x\circ y & = y\circ x \\ &= \d{x}\,y \\ &= \d{y}\,x \\ }$$