polynom (version 1.4-0)

polynomial: Polynomials

Description

Construct, coerce to, test for, and print polynomial objects.

Usage

polynomial(coef = c(0, 1))
as.polynomial(p)
is.polynomial(p)

# S3 method for polynomial as.character(x, decreasing = FALSE, …) # S3 method for polynomial print(x, digits = getOption("digits"), decreasing = FALSE, …)

Arguments

coef

numeric vector, giving the polynomial coefficients in increasing order.

p

an arbitrary R object.

x

a polynomial object.

decreasing

a logical specifying the order of the terms; in increasing (default) or decreasing powers.

digits

the number of significant digits to use for printing.

potentially further arguments passed to and from other methods.

Details

polynomial constructs a polynomial from its coefficients, i.e., p[1:k] specifies the polynomial $$p_1 + p_2 x + p_3 x^2 + \dots + p_k x^{k-1}.$$ Internally, polynomials are simply numeric coefficient vectors of class "polynomial". Several useful methods are available for this class, such as coercion to character (as.character()) and function (as.function.polynomial), extraction of the coefficients (coef()), printing (using as.character), plotting (plot.polynomial), and computing sums and products of arbitrarily many polynomials.

as.polynomial tries to coerce its arguments to a polynomial.

is.polynomial tests whether its argument is a polynomial (in the sense that it has class "polynomial".

Examples

Run this code
# NOT RUN {
polynomial(1:4)
p <- as.polynomial(c(1,0,3,0))
p
print(p, decreasing = TRUE)
stopifnot(coef(p) == c(1,0,3))

polynomial(c(2,rep(0,10),1))
# }

Run the code above in your browser using DataLab