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.
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.
Author(s)
Bill Venables, with some code inherited from the original package
by Bill Venables and Kurt Hornik.
Maintainer: <Bill.Venables@gmail.com>
References
None.
Examples
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)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(PolynomF)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/PolynomF/PolynomF-package.Rd_%03d_medium.png", width=480, height=480)
> ### Name: PolynomF-package
> ### Title: Univariate polynomial objects in R
> ### Aliases: PolynomF-package PolynomF
> ### Keywords: symbolmath
>
> ### ** Examples
>
> x <- polynom()
> p <- (x-1)^2 + 1
> p
2 - 2*x + x^2
> plot(p)
>
> pv <- p(-3:4); pv
[1] 17 10 5 2 1 2 5 10
>
> p1 <- p(p-1); p1;
1 + 4*x^2 - 4*x^3 + x^4
> 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
List of polynomials:
[[1]]
1
[[2]]
x
[[3]]
-1 + x^2
[[4]]
-3*x + x^3
[[5]]
3 - 6*x^2 + x^4
[[6]]
15*x - 10*x^3 + x^5
[[7]]
-15 + 45*x^2 - 15*x^4 + x^6
[[8]]
-105*x + 105*x^3 - 21*x^5 + x^7
[[9]]
105 - 420*x^2 + 210*x^4 - 28*x^6 + x^8
[[10]]
945*x - 1260*x^3 + 378*x^5 - 36*x^7 + x^9
[[11]]
-945 + 4725*x^2 - 3150*x^4 + 630*x^6 - 45*x^8 + x^10
> ### 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)
0 with absolute error < 0
> f(4,4)
1 with absolute error < 2.7e-05
>
>
>
>
>
> dev.off()
null device
1
>