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.

This question already has an answer here:

I am having trouble correctly substituting a matrix into an (originally) scalar equation.

For example:

A = {{3, 1}, {1, 2}}
cp = CharacteristicPolynomial[A, x]

which produces x^2-5x+5

It is known that the characteristic polynomial must be equal to zero. Using:

cp /. {x -> A}

We obtain {{-5, 0}, {0, -5}}, but the correct answer is {{0, 0},{0, 0}} or,

MatrixPower[A, 2] - 5 A + 5 IdentityMatrix[2]

I have toyed with the idea of using CoefficientList and an If statement inside of a For loop, then matching the coefficients with their respective MatrixPower and multiplying the final CoefficientList[A, x, 0] by the identity matrix. But, this seems unnecessarily complex and not general enough to work for all characterist polynomial forms.

Can anyone think of an elegant way to raise the matrix to the correct power using MatrixPower and also only multiply the constant term by the identity matrix?

share|improve this question

marked as duplicate by Jens, rasher, Michael E2, Sjoerd C. de Vries, bobthechemist May 25 at 14:24

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.

1 Answer 1

up vote 2 down vote accepted

This comes straight from the documentation on CharacteristicPolynomial. Look at the section Examples > Properties & Relations.

m = {{3, 1}, {1, 2}};
cp = CharacteristicPolynomial[m, x]
5 - 5 x + x^2
cl = CoefficientList[cp, x];
Sum[MatrixPower[m, j - 1] cl[[j]], {j, 1, Length[cl]}]
{{0, 0}, {0, 0}}
share|improve this answer
    
To avoid opening another question, is there an easy way to solve CharacteristicPolynomial for the highest power? In this example, set cp=5(x-1)? Obviously I can do cp=-(cp-x^2) but is there a better way? –  gKirkland May 26 at 23:37
    
@gKirkland. Please do open a new question on this new issue. We like to keep questions focused to one issue whenever we can. –  m_goldberg May 27 at 1:18

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