Skip to contents

stm_charpoly() calculates the characteristic polynomial of a square matrix and optionally returns the polynomial as an equation.

Usage

stm_charpoly(x, equation = FALSE, variable = "x", digits = NULL)

Arguments

x

A square matrix for which the characteristic polynomial will be computed.

equation

Logical. If TRUE, the polynomial is returned as a string equation. Default is FALSE.

variable

A string specifying the variable to be used in the polynomial. Default is "x".

digits

Optional. An integer specifying the number of decimal places to round the result. Default is NULL, which means no rounding.

Value

A numeric vector of polynomial coefficients or a string representation of the polynomial if equation = TRUE.

Details

The function calculates the characteristic polynomial of a square matrix using pracma::charpoly(). If equation = TRUE, the coefficients are formatted as a polynomial equation.

See also

Examples

A <- matrix(c(4, 1, 2, 3), nrow = 2)
stm_charpoly(A)
#> [1]  1 -7 10
stm_charpoly(A, equation = TRUE)
#> [1] "1 * x^3 - 7 * x^2 + 10 * x^1"
stm_charpoly(A, equation = TRUE, variable = "t")
#> [1] "1 * t^3 - 7 * t^2 + 10 * t^1"