Learn R Programming

PolynomF (version 0.94)

PolynomF-package: Univariate polynomial objects in R

Description

A package to implement a class of objects that behave like univariate polynomails. Arithmetic operations (addition, subtraction, multiplication, division, remainder, raising to a non-negative integer power) are supported in a natural way. The objects also act as R functions. This package is a successor to the `polynom' package, but has a simpler and more convenient representation for the objects. Like `polynom' it uses S3 classes and methods.

Arguments

Details

Package: PolynomF
Type: Package
Version: 1.0
Date: 2008-05-05
License: GPL-2
LazyLoad: yes

The constructor function polynom is used to create polynomial objects from their coefficient vector, in power series order. Once polynomials are constructed they may used as objects in arithmetic operations, integration and differentiation, and as R functions that evaluate the polynomial either at a numeric or complex vector, or at another polynomial, i.e. substituting one polynomial into another. Facilities are also provided for graphical presentation and calculation of complex zeros.

The constructor function polylist may be used to create a list of polynomial objects. Operations on polylist objects include simultaneous graphical display of all components and coercion to function. The function may then be used to evaluate all all polynomials on the list simultaneously at the same argument.

References

None.

Examples

Run this code
# NOT RUN {
x <- polynom()
p <- (x-1)^2 + 1
p
plot(p)

pv <- p(-3:4); pv

p1 <- p(p-1); p1;
plot(polylist(p, p1))

## Hermite polynomials to degree 10
H <- polylist(1, x)
for(n in 2:10)
    H[[n+1]] <- x*H[[n]] - (n-1)*H[[n-1]]
H
### normalisation to unit length
for(n in 1:11)
    H[[n]] <- H[[n]]*exp(-lgamma(n)/2)

plot(H, xlim = c(-3,3))

## orthogonality relationship check:
f <- function(i,j) stats::integrate(function(z)
      dnorm(z)*H[[i+1]](z)*H[[j+1]](z), -Inf, Inf)

f(2,3)
f(4,4)
# }

Run the code above in your browser using DataLab