Gradient of a trace with $\mbox{diag}$ and Kronecker product I have a function about the trace of a matrix
$$f(\mathbf{h})=\mathrm{tr} \left( \mathbf{F} \left( \mathbf{I}_N \otimes \mathrm{diag}(\mathbf{h})) \mathbf{A} (\mathbf{I}_N \otimes \mathrm{diag}(\mathbf{h}) \right) \mathbf{F}^\mathrm{H} \right)$$
where $\mathbf{I}_N$ is the identity matrix. What is $\frac{\partial f}{\partial \mathbf{h}}$?

The most related questions I could find:

*

*Derivative of a trace with Kronecker product


*Replace $X$ with $\mbox{diag}(x)$ in trace matrix derivative identity
 A: I will answer my question by myself.
Just a slight modification of the answer in
Replace $X$ with $\mbox{diag}(x)$ in trace matrix derivative identity
$\frac{\partial f}{\partial \mathbf{h}} = (\mathbf{1}_{1 \times N} \otimes \mathbf{I}_M) (\mathrm{diag}^{-1}(\mathbf{A}\mathrm{diag}(\mathbf{I}_N \otimes \mathrm{diag}(\mathbf{h}))\mathbf{F}^\mathrm{H}\mathbf{F}) + \mathrm{diag}^{-1}(\mathbf{F}^\mathrm{H}\mathbf{F}\mathrm{diag}(\mathbf{I}_N \otimes \mathrm{diag}(\mathbf{h}))\mathbf{A}))$
where $M$ is the length of $\mathbf{h}$.
But I am still wondering if there is a simpler form.
A: $
\def\o{{\large\tt1}}\def\p{\partial}
\def\L{\left}\def\R{\right}\def\LR#1{\L(#1\R)}
\def\vecc#1{\operatorname{vec}\LR{#1}}
\def\Unvecc#1{\operatorname{Mat}\LR{#1}}
\def\diag#1{\operatorname{diag}\LR{#1}}
\def\Diag#1{\operatorname{Diag}\LR{#1}}
\def\trace#1{\operatorname{Tr}\LR{#1}}
\def\qiq{\quad&\implies\quad}
\def\grad#1#2{\frac{\p #1}{\p #2}}
$Define the matrix variables
$$\eqalign{
B &= F^HF \\
H &= \Diag h \qiq dH = \Diag{dh} \\
X &= \LR{I\otimes H} \qiq dX = I\otimes dH \\
  &= \Diag{\o\otimes h} \\
C &= \big(AXB + BXA&\big)^T \\
}$$
and write the function as
$$\eqalign{
f &= \trace{AXBX} \\&= A^T:XBX \\
df &= A^T:\LR{dX\,BX+XB\;dX} \\
 &= \LR{A^TX^TB^T+B^TX^TA^T}:dX \\
 &= C:\Diag{\o\otimes dh} \\
 &= \diag C:\LR{\o\otimes dh} \\
 &= \diag C:\vecc{dh\,\o^T} \\
 &= \Unvecc{\diag C}:\LR{dh\,\o^T} \\
 &= \Unvecc{\diag C}\,\o:dh \\
\grad{f}{h} &= \Unvecc{\diag C}\,\o \\
}$$
where
$\;\o\;$ is the all-ones vector,
diag() creates a vector from the main diagonal of a matrix, Diag() creates a diagonal matrix from a vector,
vec() stacks the columns of a matrix to create a long vector, and
Mat() undoes vec() to regenerate a matrix from a long vector.
Finally, a colon is used as a convenient shorthand for the trace, i.e.
$$\eqalign{
A:B &= \sum_{i=1}^m\sum_{j=1}^n A_{ij}B_{ij} \;=\; \trace{A^TB} \\
A:A &= \big\|A\big\|^2_F \\
}$$
