Derivative of a Function of the Diag function

derivativesmatrix-calculustrace

Suppose there is a vector $U \in \mathbb{R}^n$. How would you find the derivative of:

$$
F(U)=trace\left(diag(U) A\ diag(U) \right)
$$

where $A \in \mathbb{R}^{n \times n} \succ 0 $ and where $diag(\cdot)$ creates a diagonal matrix with $(\cdot)$ on the leading diagonal. Where the derivative is taken with respect to the vector $U$, i.e.

$$
{\partial F(U) \over \partial U } \\
$$

I am more interested in the method used. Thanks in advance.

Best Answer

Posting the solution I identified.

Due to the trace operator evaluating the above is equivalent to evaluating:

$$ {\partial \left(\sum\limits_{i=1}^{n} u_i \ A_{(i,i)}u_i\right)\over \partial U }= \left( \begin{align} \begin{array} {\partial \left(\sum\limits_{i=1}^{n} u_iA_{(i,i)}u_i\right)\over \partial u_1}\\ {\partial \left(\sum\limits_{i=1}^{n} u_iA_{(i,i)}u_i\right)\over \partial u_1}&\\ \vdots \ \ \ \ \ \ \ \ \ \ \ &\\ {\partial \left(\sum\limits_{i=1}^{n} u_iA_{(i,i)}u_i\right)\over \partial u_n}&\\ \end{array}\end{align}\right) \\ $$

which becomes:

$$ {\partial \left( trace(diag(U)\ A\ diag(U)) \right)\over \partial U} = 2\ diag( A) U $$

Related Question