# Derivate of powers of stochastic matricies with respect to its elements

Let $$\mathbf{X} \in \mathbb{R}^{k \times k}$$ be a square stochastic matrix (i.e $$\mathbf{1}\mathbf{X} = \mathbf{1}$$), are there any useful identities that can possibly be used to simplify the expression $$\frac{\partial \mathbf{X}^n}{\partial X_{ij}}$$, where $$n \in \mathbb{Z}^+$$ raises $$\mathbf{X}$$ to the $$n$$-th power and $$X_{ij}$$ is the element corresponding to the index $$i,j$$ in matrix $$\mathbf{X}$$.

During my search on StackExchange, I have come across greg's answer, stating that $$\frac{\partial F}{\partial\mathbf{X}_{ij}} = \sum_{k=1}^\infty \alpha_k(\sum_{l=1}^k\mathbf{X}^{k-l}\mathbf{E}_{ij}\mathbf{X}^{l-1})$$ where $$F(\mathbf{X}) = \sum_{k=0}^\infty \alpha_k \mathbf{X}^k$$ and $$\mathbf{E}_{ij} = e_ie_j^T$$

where $$e_i$$ is a cartesian basis vector and $$\mathbf{E}_{ij}$$ is the single-entry matrix.

Would anyone please tell me how this identity is derived or the name of this identity/theorem? Thank you so much!

In the same post that you linked to, I believe that Ruy's answer shows how that identity is derived (for fixed $$k$$). For $$F(X) = X^n$$, note that $$\frac{\partial X^n}{\partial X_{ij}} = F'(X)(E_{ij}) = \left. \frac{\mathrm{d}}{\mathrm{d}t} \right|_{t=0} (X + t E_{ij})^n$$: this is to be interpreted in the multivariable calculus way as the directional derivative of $$F$$ in the direction $$E_{ij} = e_i e_j^T$$ (i.e. the standard basis direction for the $$(i, j)$$th coordinate). Thus, as the answer shows, this evaluates to $$E_{ij} X^{n-1} + X E_{ij} X^{n-2} + X^2 E_{ij} X^{n-3} + \dots + X^{n-2} E_{ij} X + X^{n-1} E_{ij} = \sum_{\ell=1}^n X^\ell E_{ij} X^{n-1-\ell} ,$$ which is the same as the term in the infinite series version you are referencing up to a change of variables. (Why? Expand out $$(X + t E_{ij})^n$$; the only terms remaining after differentiating with respect to $$t$$ and sending $$t$$ to zero are the ones with a single $$E_{ij}$$ term in it.)