# Correctly substituting a matrix into a scalar equation [duplicate]

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?

-

## marked as duplicate by Jens, ciao, Michael E2, Sjoerd C. de Vries, bobthechemistMay 25 '14 at 14:24

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}}

-
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 '14 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 '14 at 1:18