Learn R Programming

tsdecomp (version 0.2)

polyeval: Polynomial Operations and Utilities

Description

Polynomial operations and utilities.

Usage

polystring(x, varchar = "x", brackets = FALSE, ndec = 2, emptychar = "") polyeval(p, x) polyprod(x, y, tol = 1.490116e-08) polydiv(x, y) roots2poly(x)

Arguments

x
numeric vector containing the coefficients of the polynomial (in increasing order and without gaps). For polyeval, this is the point at which the polynomial is to be evaluated. For roots2poly, this is a numeric vector containing the roots of the polynomial.
y
numeric vector containing the coefficients of the polynomial (in increasing order and without gaps).
p
numeric vector containing the coefficients of the polynomial (in increasing order and without gaps).
varchar
character string, the label to be printed representing the variable of the polynomial, defaults to "x".
brackets
logical, if TRUE the polynomial is printed within parentheses.
ndec
integer, coefficients are rounded up to this number of decimals.
emptychar
the character string to be printed if the polynomial is empty.
tol
a numeric, tolerance below which coefficients are set to zero.

Details

polystring returns a string of a numeric vector in the format of a polynomial.

polyeval evaluates the polynomial defined in the vector of coefficients p at the point x.

polyprod performs polynomial multiplication.

polydiv performs polynomial division (returning the quotient and the remainder).

roots2poly computes the coefficients of a polynomial from its roots.

See Also

polyroot.

Examples

Run this code
# print a fitted ARMA model
set.seed(123)
y <- arima.sim(n=120, model=list(ar=c(0.8, -0.3), ma=0.6))
fit <- arima(y, order=c(2,0,1), include.mean=FALSE)
cat(paste0(
polystring(c(1, -fit$model$phi), brackets=TRUE, ndec=3), "y_t = ",
polystring(c(1, fit$model$theta), brackets=TRUE, ndec=3), "e_t\n"))

# convert roots to coefficients
p <- c(1, 0.8, -0.3)
cat(polystring(p))
r <- polyroot(p)
roots2poly(r)

Run the code above in your browser using DataLab