Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm attempting to calculate the exponential of a matrix via Cayley-Hamilton theorem. (Following the "concrete example" from http://en.wikipedia.org/wiki/Cayley%E2%80%93Hamilton_theorem)

I am having trouble manipulating the characteristic polynomial:

A[1] = {{1, 2}, {3, 4}};
cp = CharacteristicPolynomial[A[1], x]
A[2] = x^2 - cp
A[2] = A[2] /. {x -> A[1]}

This is the form of the example. Now, I can't figure out a way to multiply only the +2 by the identity matrix, while substituting in x->A[1]. The correct result should be

5 A[1] + 2 *IdentityMatrix[2]

which obviously does not match

A[2] = A[2] /. {x -> A[1]}

As the "+2" is applied to all elements of A[1], not just the diagonals.

share|improve this question
2  
This exact problem is solved in the Documentation for MatrixPower, last example under Applications. –  Jens May 15 at 1:36
add comment

2 Answers 2

up vote 4 down vote accepted

To expand on David's answer, you need to replace it with the correct function. It turns out the pattern to do this is a little tricky to get right, either that or I'm out of practice. So, I'll walk you through the process using f as the "correct" function.

Initially, I would propose attempting to match using a default exponent, n_.,

cp /.  x^n_. :>  f[x, n]
(* -2 - 5 f[x, 1] + f[x, 2] *)

which as you see does not match the x^0 term. So, it seems we need to deal with that term directly,

cp /.  {x^(n_.)  :>  f[x, n], c_?NumericQ :> c f[x, 0]}
(* -2 f[x, 0] - 5 f[x, 0] f[x, 1] + f[x, 2] *)

which is over aggressive. To tone it down, we need to add a leading coefficient,

cp /.  {c_. x^(n_.)  :>  c f[x, n], c_?NumericQ :> c f[x, 0]}
(* -2 f[x, 0] - 5 f[x, 1] + f[x, 2] *)

which we also make optional so it will match x^2.

Now, applying this to your exact problem, we substitute f for the correct function: MatrixPower, e.g.

x^2 - cp /. {c_. x^(n_.) :> c MatrixPower[A[1], n], 
   c_?NumericQ :> c MatrixPower[A[1], 0]}
(* {{7, 10}, {15, 22}} *)

which is the correct answer

MatrixPower[A[1], 2]
(* {{7, 10}, {15, 22}} *)
share|improve this answer
add comment

Remember that (A[1])^2 is not the same as A[1].A[1]. So you need to recode all of the powers (greater than one) in the characteristic polynomial into the form of MatrixPowers.

share|improve this answer
    
The purpose of using Cayley - Hamilton is to avoid using matrix powers. So, I'm not sure how your comment relates to my problem? –  gKirkland May 15 at 1:18
2  
@gKirkland he's absolutely correct. The distinction is x^2 is interpreted as Power[x, 2], but if x is a matrix, then every element is squared. This helps speed up some types of calculations. –  rcollyer May 15 at 1:24
2  
One cannot fully avoid all matrix powering, even in using Cayley-Hamilton. It allows one to write powers higher than n in terms of the powers up to n. –  Daniel Lichtblau May 15 at 14:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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