Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

My matrix is

$\qquad A= \begin{pmatrix} {1} & {2} & {3}\\ {4} & {1} & {0}\\ {0} & {5} & {4} \end{pmatrix} $

I need

$\qquad A^n$

I tried

MatrixPower[A, n]

I do not understand the result. Should it not go according to n


[by m_goldberg]

The result the OP is complaining about is full of root objects and looks like this:

Shallow[MatrixPower[{{1, 2, 3}, {4, 1, 0}, {0, 5, 4}}, n], 6]


share|improve this question

marked as duplicate by Jens, MarcoB, Louis, rhermans, Mr.Wizard Feb 17 at 17:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

The result should be an expression valid for arbitrary $n$. What precisely were you expecting? – J. M. Feb 17 at 3:29
I do not understand this result, I can explain how it is interpreted, it took no time with Mathematica Root[-32 + #1 - 6 #1^2 + #1^3 &, 1]^ n Root[-540 + 4543 #1 - 12952 #1^2 + 12952 #1^3 &, 1] + ( Root[-32 + #1 - 6 #1^2 + #1^3 &, 2]^n) – wally Feb 17 at 3:34
Have a look at the docs for Root[] and this thread to help you understand your result. You might want to apply ToRadicals[] to your result if you want to see explicit (and complicated!) radical expressions. – J. M. Feb 17 at 3:39
up vote 13 down vote accepted

You need to understand that Mathematica prefers to write some numbers in their closed form because with numerical values, you would loose information and probably precision. It is kind of why it is better to keep Sin[4] and not use -0.756802, because Sin[4] can probably later in your calculation be combined or simplified with other expressions.

That being said, an easy way to understand matrix-power is to assume you can decompose your matrix A into $A=PDP^{-1}$, where D is a diagonal matrix. This is not always possible with every matrix A, but in your case it is. Please see DiagonalizableMatrixQ for more information.

If A is indeed diagonalizable, you can use

$$A^n = P D^n P^{-1}$$

and look how easy it is to calculate the power of a diagonal matrix:

Mathematica graphics

So what you can do is to calculate D and P by

A = {{1, 2, 3}, {4, 1, 0}, {0, 5, 4}};
{p, d} = JordanDecomposition[A];

Looking at d, you see the same Root objects

Mathematica graphics

The components in on the diagonal, really just mean the 1st, 2nd and 3rd root of a special polynomial: the characteristic polynomial of the matrix A. You can compute it with

CharacteristicPolynomial[A, x]
(* 32 - x + 6 x^2 - x^3 *)

and you can find the roots by a simple

Solve[-32 + x - 6 x^2 + x^3 == 0, x]

Now, it is important to see that you get the same numerical values by using ToRadicals[d]. Compare them!

Finally, you can easily write down your matrix power with p and d and of course, you can compare it to what MatrixPower gives as answer (might take a while)

FullSimplify[p.d^n.Inverse[p] == MatrixPower[A, n], n > 0]
(* True *)
share|improve this answer
I'm sure you know this, but $\mathbf D$ won't be diagonal in general, especially if the given matrix is defective. The point of using JordanDecomposition[] is that it can handle the case where the input matrix doesn't have a complete eigenvector set. The OP was fortunate here that his matrix was diagonalizable, tho. – J. M. Feb 17 at 4:07
Yes, I was very close to mention DiagonalizableMatrixQ, but I thought that might be to much information in this specific case. But I may be wrong and I should include this hint. I have added it now. – halirutan Feb 17 at 4:11
On another note, you might also want to mention CharacteristicPolynomial[] so that OP can see where the stuff within Root[] might have come from. – J. M. Feb 17 at 4:14
Hehe.. I knew from the beginning that this answer would be too large and should not be given here :) – halirutan Feb 17 at 4:15
Well, yeah, apart from the question of what Root[] is, this really is a math question. ;) – J. M. Feb 17 at 4:17

Mathematica has given you what you asked for. You can see that this is true by looking at the values it takes for values of n = 0, 1, 2, 3.

a = {{1, 2, 3}, {4, 1, 0}, {0, 5, 4}};
b[n_Integer] := Chop[N[MatrixPower[a, n]]]
Column[Table[MatrixForm[b[i]], {i, 0, 3}]]


share|improve this answer
It would probably be more convincing to use RootReduce[] instead of Chop[] + N[], methinks. For further fun, OP can check that b[-1] will give the same result as Inverse[a]. – J. M. Feb 17 at 4:09
@J.M. I don't disagree with your comment, but I still think my answer is reasonably convincing – m_goldberg Feb 17 at 5:32
I did upvote your post before commenting, tho; it just feels unseemly to me to use N[] to show that the result of an appropriate linear combination of various radicals results in an integer. – J. M. Feb 17 at 5:38
FullSimplify yields the exact integer results as well – george2079 Feb 17 at 14:52
Thanks to all ... – wally Feb 17 at 15:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.