%% Matrix Evaluation of Characteristic Polynomial
% Find the characteristic polynomial of a Pascal Matrix of order 4.

X =  pascal(4)
p = poly(X)

% The characteristic polynomial is
% p(x) = x^4 - 29x^3 + 72x^2  -29x + 1
% Pascal matrices have the property that the vector of coefficients of the characteristic polynomial is the same forward and backward (palindromic).
%
% Substitute the matrix, X, into the characteristic equation, p. The result is very close to being a zero matrix. This example is an instance of the Cayley-Hamilton theorem, where a matrix satisfies its own characteristic equation.

Y = polyvalm(p,X)

% Copyright 2015 The MathWorks, Inc.