Characteristic polynomial of matrix
charpoly(A) returns a vector of the coefficients of the characteristic polynomial of A. If A is a symbolic matrix, charpoly returns a symbolic vector. Otherwise, it returns a vector of double-precision values.
Free symbolic variable.
Default: If you do not specify var, charpoly returns a vector of coefficients of the characteristic polynomial instead of returning the polynomial itself.
Compute the characteristic polynomial of the matrix A in terms of the variable x:
syms x; A = sym([1 1 0; 0 1 0; 0 0 1]); charpoly(A, x)
ans = x^3 - 3*x^2 + 3*x - 1
To find the coefficients of the characteristic polynomial of A, call charpoly with one argument:
A = sym([1 1 0; 0 1 0; 0 0 1]); charpoly(A)
ans = [ 1, -3, 3, -1]
Find the coefficients of the characteristic polynomial of the symbolic matrix A. For this matrix, charpoly returns the symbolic vector of coefficients:
A = sym([1 2; 3 4]); P = charpoly(A)
P = [ 1, -5, -2]
Now find the coefficients of the characteristic polynomial of the matrix B, all elements of which are double-precision values. Note that in this case charpoly returns coefficients as double-precision values:
B = ([1 2; 3 4]); P = charpoly(B)
P = 1 -5 -2
 Cohen, H. "A Course in Computational Algebraic Number Theory." Graduate Texts in Mathematics (Axler, Sheldon and Ribet, Kenneth A., eds.). Vol. 138, Springer, 1993.
 Abdeljaoued, J. "The Berkowitz Algorithm, Maple and Computing the Characteristic Polynomial in an Arbitrary Commutative Ring." MapleTech, Vol. 4, Number 3, pp 21–32, Birkhauser, 1997.