Learn R Programming

polynomial (version 0.1.0)

polynomial: Polynomials

Description

Functions to create, coerce and check for polynomials.

Usage

polynomial(length = 0)
as.polynomial(x, exponents = NULL, ...)
is.polynomial(x)

Arguments

length

A non-negative integer specifying the desired length. Double values will be coerced to integer: supplying an argument of length other than one is an error.

x

object to be coerced or tested.

exponents

NULL or an integer vector of the same length as x.

further arguments passed to as.numbers.

Value

polynomial and as.polynomial both return polynomial objects.

is.polynomial returns TRUE or FALSE depending on whether its argument is a polynomial or not.

Details

polynomial creates a double-precision vector of the specified length with each coefficient equal to 0 and exponents equal to seq(0L, length.out = length).

as.polynomial returns x if x is a polynomial. If not, it attempts to coerce its argument to be of double or complex type: most attributes will be stripped (excluding dim, dimnames and names). Finally, the "class" and "exponents" attibutes are populated.

Examples

Run this code
# NOT RUN {
as.polynomial(c(0, 4, 2, -1))


## 'as.polynomial' reduces complex numbers to real numbers if appropriate.
## You can use 'strict = FALSE' to stop this conversion.
as.polynomial(complex(real = c(0, 4, 2, -1)))
as.polynomial(complex(real = c(0, 4, 2, -1)), strict = FALSE)
# }

Run the code above in your browser using DataLab