charpoly.RdComputes the characteristic polynomial (and the inverse of the matrix, if requested) using the Faddeew-Leverrier method.
charpoly(a, info = FALSE)Computes the characteristic polynomial recursively. In the last step the determinant and the inverse matrix can be determined without any extra cost (if the matrix is not singular).
Either the characteristic polynomial as numeric vector, or a list with
components cp, the characteristic polynomial, det, the
determinant, and inv, the inverse matrix, will be returned.
Hou, S.-H. (1998). Classroom Note: A Simple Proof of the Leverrier–Faddeev Characteristic Polynomial Algorithm, SIAM Review, 40(3), pp. 706–709.
a <- magic(5)
A <- charpoly(a, info = TRUE)
#> Error term: 0
A$cp
#> [1] 1 -65 -625 40625 78000 -5070000
roots(A$cp)
#> [1] 65.00000 -21.27677 21.27677 -13.12628 13.12628
A$det
#> [1] 5070000
zapsmall(A$inv %*% a)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 0 0 0 0
#> [2,] 0 1 0 0 0
#> [3,] 0 0 1 0 0
#> [4,] 0 0 0 1 0
#> [5,] 0 0 0 0 1