I would like to derivative of a scalar function with respect to matrix. In pariticular,
For given vector $v \in \mathbb{R}^n$, let $f(A)=v^\top A^n v$ for any integer $n\in\mathbb{N}$. I want to find $\nabla_A (v^\top A^n v)$
When $n=1$, $$\nabla_A (v^\top A v) = v^\top v$$ and for $n=2$, $$\nabla_A(v^\top A^2 v) = Avv^\top + vv^\top A^\top$$ But I don't know how to obtain derivative for general $n$. Is there general form of derivative?
For convenience, define a new symmetric matrix variable $$V = vv^T = V^T$$
Then the function can be written in terms of the Frobenius (:) Inner Product and this new variable. And its differential and gradient can be derived as $$\eqalign{ \cr f &= V:A^n \cr\cr df &= V:dA^n \cr &= V:\sum_{k=0}^{n-1} A^k\,dA\,A^{n-1-k} \cr &= \sum_{k=0}^{n-1} \Big(A^k\,V\,A^{n-1-k}\Big)^T : dA \cr\cr \frac{\partial f}{\partial A} &= \sum_{k=0}^{n-1} \Big(A^k\,V\,A^{n-1-k}\Big)^T \cr\cr }$$ Depending on the layout convention used, the gradient might be the transpose of this expression.