Code to calculate characteristic polynomial?


I’m referring to

det(\lambda I - A)

I’m not finding a function to calculate this (it’s charpoly in Matlab).

Happy to write my own, just want to make sure i’m not duplicating effort.


p.s. well actually i’m probably not “happy” to write my own, i sure it’s non-trivial…


Why do you need this? For numerical calculations, the coefficients of the characteristic polynomial are generally useless (because even a tiny error in the coefficients radically changes the roots).


for Cayley Hamilton. i wanted to play with it as a method for matrix multiplication. Not as a serious method to calculate it, just for educational purposes.

Looks like this works.

julia> using LinearAlgebra

julia> using Polynomials

julia> a=[[1,3] [2,4]]
2×2 Array{Int64,2}:
 1  2
 3  4
julia> poly(eigvals(a))
Poly(-1.9999999999999998 - 5.0*x + 1.0*x^2)

That was easy.