({{, (RefLink[MatrixExp, paclet:ref/MatrixExp])[m]
gives the matrix exponential of m. }, {, (RefLink[MatrixExp, paclet:ref/MatrixExp])[m,v]
gives the matrix exponential of m applied to the vector v.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[MatrixExp, paclet:ref/MatrixExp])[m] effectively evaluates the power series for the exponential function, with ordinary powers replaced by matrix powers.

(RefLink[MatrixExp, paclet:ref/MatrixExp]) works only on square matrices.

In (RefLink[MatrixExp, paclet:ref/MatrixExp])[m,v] the matrix m can be a (RefLink[SparseArray, paclet:ref/SparseArray]) object.

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Exponential of a 2×2 matrix:

MatrixExp[{{1.2,5.6},{3,4}}]

MatrixExp[{{0,1},{-1,0}} t]

Exponential applied to a vector:

MatrixExp[{{1.2,5.6},{3,4}},{1,2}]

OpenersExampleSection1(Spacer1)Scope  (4)

Use exact arithmetic to compute the matrix exponential:

m={{2,0,0},{0,1,-1},{0,1,1}};

MatrixExp[m]

Use machine arithmetic:

MatrixExp[N[m]]

Use 24-digit precision arithmetic:

MatrixExp[N[m, 24]]

Find the matrix exponential of a complex matrix:

m=RandomComplex[1+I,{3,3}];

MatrixExp[m]

The exponential of a symbolic matrix:

m={{2,0,0},{0,1,-1},{0,1,1}};

MatrixExp[m t]

Exponential of a sparse 100×100 matrix:

MatrixExp[SparseArray[Band[{1,-1},{100,100}]->2],Range[100]]

OpenersExampleSection3(Spacer1)Applications  (2)

A system of first-order linear differential equations:

system = ({{x'[t] == z[t]}, {y'[t] == y[t] - z[t]}, {z'[t] == -x[t]}});

Write the system in the form v'(t)==a.v(t) with v(t)={x(t),y(t),z(t)}:

a = (({{0, 0, 1}, {0, 1, -1}, {-1, 0, 0}}));

The matrix exponential gives the basis for the general solution:

MatrixExp[a t]//MatrixForm

DSolve[system,{x[t],y[t],z[t]},t]

The matrix exponential applied to a vector gives a particular solution:

MatrixExp[a t,{1,0,0}]//MatrixForm

DSolve[{system, {x[0] == 1, y[0] == 0, z[0] == 0}}, {x[t], y[t], z[t]},t]

The matrix s approximates the second derivative periodic on [-L,L] on the grid x:

L = 10;
n = 500;
x = L*(2N[Range[n]]/n - 1);
s = N[Block[{h = 2. L/ n},(1/(h^2))SparseArray[{{i_, i_}->-2, {i_, j_}/;Abs[i-j]==1->1,{1,n}->1, {n,1}->1},{n,n}]]]

A vector representing a soliton on the grid x:

u = Sech[x +Pi ] Exp[Pi I x];
ListPlot[Transpose[{x,Abs[u]}]]

Propagate the solution of i ((∂u)/(∂t))==2 ((|u|)^2)u+(((∂^2)u)/(∂(x^2))) using a splitting (e^(A+B))==(e^(A/2))  (e^B)(e^(A/2))+O(((Δt)^2)):

Timing[Module[{Δt = 0.05, m},
m = Δt (0. + 1. I) s;
Do[
u = Exp[Δt I u Conjugate[u]] u;
u = MatrixExp[m,u];
u = Exp[Δt I u Conjugate[u]] u,
{1/Δt}]]]

Plot the solution and 10 times the error from the solution of the cubic Schrödinger equation:

ListPlot[{Transpose[{x,Abs[u]}], Transpose[{x, 10Abs[u - Sech[x- Pi]Exp[I(Pi  x + (1 - Pi^2))]]}]}, PlotRange->All]

OpenersExampleSection4(Spacer1)Properties & Relations  (4)

The matrix exponential of a diagonal matrix is diagonal:

d={1,2,3,4};

MatrixExp[DiagonalMatrix[d t]]

DiagonalMatrix[Exp[d t]]

The matrix exponential of a nilpotent matrix is a polynomial matrix:

n={{0,2,3,4},{0,0,5,6},{0,0,0,7},{0,0,0,0}};

MatrixExp[n t]//MatrixForm

(RefLink[MatrixExp, paclet:ref/MatrixExp])[m] is always invertible, and the inverse is given by (RefLink[MatrixExp, paclet:ref/MatrixExp])[-m]:

m=KroneckerProduct[RandomReal[1,3],RandomReal[1,3]];

{MatrixRank[m],MatrixRank[MatrixExp[m]]}

MatrixExp[m].MatrixExp[-m]//Chop

If m is diagonalizable with m=(v^(-1)).d.v then exp(m)=v.exp(d).v:

m=RandomReal[1,{3,3}];

{d, vt} = Eigensystem[m]

v = Transpose[vt];
v.DiagonalMatrix[Exp[d]].Inverse[v] - MatrixExp[m]//Chop

OpenersExampleSection5(Spacer1)Possible Issues  (1)

For a large sparse matrix, computing the matrix exponential may take a long time:

Block[{n = 1000},
v = RandomComplex[1 + I, 1000];
s = N[SparseArray[{{i_, i_}->-2 I, {i_, j_}/;Abs[i-j]==1->I,{1,n}->I, {n,1}->I},{n,n}, (0. + 0. I)]]]

Timing[m = MatrixExp[s];]

Computing the application of it to a vector uses less memory and is much faster:

Timing[ev = MatrixExp[s, v];]

The results are essentially the same:

Max[Abs[ev - m.v]]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

m=Reverse@IdentityMatrix[20];

FullSimplify[MatrixExp[m t]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MatrixPower, paclet:ref/MatrixPower])  ▪  (RefLink[Dot, paclet:ref/Dot])  ▪  (RefLink[JordanDecomposition, paclet:ref/JordanDecomposition])  ▪  (RefLink[QRDecomposition, paclet:ref/QRDecomposition])  ▪  (RefLink[MatrixLog, paclet:ref/MatrixLog])  ▪  (RefLink[MatrixFunction, paclet:ref/MatrixFunction])  ▪  (RefLink[Exp, paclet:ref/Exp])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Basic Matrix Operations, paclet:tutorial/BasicMatrixOperations])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Matrix Operations, paclet:guide/MatrixOperations])}, {▪(RefLinkPlain[Matrices and Linear Algebra, paclet:guide/MatricesAndLinearAlgebra])}, {▪(RefLinkPlain[Integer Functions, paclet:guide/IntegerFunctions])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(Spacer1)▪(RefLinkPlain[(Spacer1)Implementation notes: Numerical and Related Functions, paclet:tutorial/SomeNotesOnInternalImplementation#14568])}, {(Spacer1)▪(RefLinkPlain[(Spacer1)Implementation notes: Algebra and Calculus, paclet:tutorial/SomeNotesOnInternalImplementation#12949])}})}})