Matrix exponential in Pari/GP

2013 Mar 18

For the well behaved matrices of quantum mechanics, it’s simply:

matexp(A) = {
P = mateigen(A);
(P*matdiagonal(exp(polroots(charpoly(A))))*matadjoint(P))/matdet(P)
}

using the fact that $$e^A=P×\mathrm{diag}(e^{\lambda_1},e^{\lambda_2},\ldots)\times P^{−1}$$ where \(\lambda_i\) are \(A\)’s eigenvalues and \(P\) is the matrix of eigenvectors of \(A\).

For example:

matexp([1,2;3,4])
[51.968956198705003658124484242647420628 + 0.E-37*I 74.736564567003212549882577707218180515 + 0.E-37*I]
[112.10484685050481882482386656082727077 + 0.E-36*I 164.07380304920982248294835080347469140 + 0.E-36*I]

Wolfram alpha agrees:

(51.969 | 74.7366)
(112.105 | 164.074)