We probably have tens (if not hundreds) of questions to compute a polynomial function of a matrix, usually by computing the remainder mod the characteristic polynomial. It's about time we start closing these as dupes starting with
this recent one. I've already cast a close vote with a dupe target. Please add some close votes (and more / better dupe targets if you have the time).