# Gradient and Hessian of Abs(Non-Repeated Eigenvalue) of Non-Symmetric Matrix

I would like to compute in MATLAB, without resort to automatic differentiation), the gradient, and ideally also the Hessian, of the absolute value of a non-repeated eigenvalue of a non-symmetric matrix. If the problem is easier in the case of a row stochastic matrix, I'd be interested in that special case, but would like something for the general case if possible. The intention would be, among other possible uses, to evaluate the gradient and Hessian within a numerical nonlinear optimizer.

Thanks.

Let $M$ be an $n \times n$ matrix with characteristic polynomial $P(\lambda) = \det(\lambda I - M)$. The partial derivative of this with respect to entry $m_{ij}$ is $-$ the $(j,i)$ entry of the classical adjoint of $\lambda I - M$. Since $P(\lambda) = 0$ for an eigenvalue $\lambda$, we should have $$\dfrac{\partial \lambda}{\partial m_{ij}} = \dfrac{\text{Adj}(\lambda I - M^T)_{ij}}{P'(\lambda)}$$ And then $$\dfrac{\partial |\lambda|}{\partial m_{ij}} = \dfrac{1}{|\lambda|} \text{Re}\left(\overline{\lambda} \dfrac{\partial \lambda}{\partial m_{ij}}\right)$$