({{, (RefLink[MatrixPower, paclet:ref/MatrixPower])[m,n]
gives the n(^th) matrix power of the matrix m. }, {, (RefLink[MatrixPower, paclet:ref/MatrixPower])[m,n,v]
gives the n(^th) matrix power of the matrix m applied to the vector v.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[MatrixPower, paclet:ref/MatrixPower])[m,n] effectively evaluates the product of a matrix with itself n times.

When n is negative, (RefLink[MatrixPower, paclet:ref/MatrixPower]) finds powers of the inverse of the matrix m. »

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

(RefLink[MatrixPower, paclet:ref/MatrixPower]) can be used on (RefLink[SparseArray, paclet:ref/SparseArray]) objects. »

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

MatrixPower[{{1,1},{1,2}},10]

MatrixPower[{{1,1},{1,2}},-2]

Compute for a symbolic (assumed to be integer) power:

MatrixPower[{{0,0,1},{0,2,0},{-1,0,0}}, n]

OpenersExampleSection1(Spacer1)Scope  (4)

Find the second inverse matrix power applied to a particular vector:

m = RandomReal[1, {10, 10}];
b = ConstantArray[1., 10];

MatrixPower[m, -2, b]

This is a more efficient way of computing (m^(-1)).(m^(-1)).b:

minv = Inverse[m];
minv.minv.b

Use exact arithmetic to compute the matrix power:

m = {{1,1/2,1/3,1/4},{0,1,1/3,1/4},{0,0,1,1/4},{0,0,0,1}};

MatrixPower[m,10]

Use machine arithmetic:

MatrixPower[N[m], 4]

Use 20-digit precision arithmetic:

MatrixPower[N[m,20],4]

Compute the matrix power for a complex matrix:

MatrixPower[{{1, I}, {I, 1}}, 4]

Matrix power for a sparse matrix:

m = SparseArray[{{i_,i_}->-2, {i_, j_}/;Abs[i-j]==1->1}, {7,7}]

MatrixPower[m,3]

The middle row is a stencil for a second-order approximation to the sixth derivative:

MatrixForm[%]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

Use a symbolic matrix with a symbolic power:

MatrixPower[{{0,a},{b,0}},n]

OpenersExampleSection3(Spacer1)Applications  (6)

Construct a rotation matrix as a limit of repeated infinitesimal transformations:

MatrixPower[{{1,θ/n},{-θ/n,1}},n]

Limit[%, n -> Infinity] // FullSimplify

Solve the constant coefficient system of difference equations x(n+1)==a.x(n):

a={{0,1,0},{1,0,0},{0,1,1}};

This computes the fundamental solution ϕ(n):

ϕ[n_]=MatrixPower[a,n]

Show that it satisfies equations and initial conditions:

Simplify[Thread[ϕ[n+1] ==a.ϕ[n]]]

Simplify[Thread[ϕ[0]==IdentityMatrix[3]]]

Find the matrix exponential for a matrix without a full set of eigenvectors:

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

mp = MatrixPower[m, n]

Compute the exponential as the power series for each term:

Map[Sum[#/n!, {n, 0, Infinity}] &, mp, {2}]

% == MatrixExp[m]

Get a sparse identity matrix with size, precision, and data type consistent with an input matrix:

m = SparseArray[{i_, i_}->i, {5,5}]

Sparse identity matrix with exact values:

MatrixPower[m,0]

MatrixForm[%]

Sparse identity matrix with machine-number values:

MatrixPower[N[m],0]

MatrixForm[%]

Inverse power iteration for the smallest eigenvalue of a sparse positive definite matrix:

n = 100;m = SparseArray[{{i_, i_}->2.,{i_, j_}/;Abs[i-j]==1->-1.},{n,n}, 0.]

v = Normalize[MatrixPower[m, -20, RandomReal[1,n]]];
val = Norm[m.v]

Check the error in m.v-val v:

Norm[m.v - val v]

Shifted inverse power iteration for the largest eigenvalue:

v = Normalize[MatrixPower[m - 4 MatrixPower[m,0], -20, RandomReal[1,n]]];
val = Norm[m.v]

Check the error in m.v-val v:

Norm[m.v - val v]

An easy way to evaluate a matrix polynomial:

mpe[p_, x_, m_]:= Module[{cl = CoefficientList[p,x]},
Sum[MatrixPower[m,i-1] cl[[i]],{i, Length[cl]}]]

mpe[1 + 2 x + 3 x^3, x, {{1,2},{3,4}}]

Evaluate a characteristic polynomial:

m = Reverse[IdentityMatrix[4]];

p = CharacteristicPolynomial[m,x]

mpe[p,x,m]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

If m is nonsingular, (RefLink[MatrixPower, paclet:ref/MatrixPower])[m, n].MatrixPower[m,-n] is the identity:

m = RandomReal[1, {5,5}];
n = RandomInteger[{1,9}];

Chop[MatrixPower[m,n].MatrixPower[m,-n]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Dot, paclet:ref/Dot])  ▪  (RefLink[MatrixExp, paclet:ref/MatrixExp])  ▪  (RefLink[LinearSolve, paclet:ref/LinearSolve])  ▪  (RefLink[MatrixFunction, paclet:ref/MatrixFunction])}})}})

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Matrix Operations, paclet:guide/MatrixOperations])}, {▪(RefLinkPlain[Recurrence and Sum Functions, paclet:guide/RecurrenceAndSumFunctions])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-NKS.png(Spacer1)NKS|Online, http://www.wolframscience.com/nksonline/index/search.cgi?SearchIndex=MatrixPower]) ((WebLink[A New Kind of Science, http://www.wolframscience.com/nksonline/]))}})}})