Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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 class 'polynomial'
as.character(x, decreasing = FALSE, ...)
## S3 method for class '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 + ... + 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

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))

polynom

A Collection of Functions to Implement a Class for Univariate Polynomial Manipulations

v1.4-0
GPL-2
Authors
Bill Venables [aut, cre] (S original), Kurt Hornik [aut] (R port), Martin Maechler [aut] (R port)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.