R: Coerce polynom or polylist objects to function.
as.function.polynom
R Documentation
Coerce polynom or polylist objects to function.
Description
Since polynom objects are represented as functions,
as.function.polynom simply removes the class attribute.
The function as.function.polylist produces allows all
polynomials on the list to be evaluated simultaneously at the same
argument value.
Usage
## S3 method for class 'polynom'
as.function(x, variable = "x", ...)
## S3 method for class 'polylist'
as.function(x, ...)
Arguments
x
A polynom or polylist object.
variable
A character string giving the name to be used for the
formal argument of the resulting function, (for as.polynom
only).
...
Not currently used.
Details
Since polynom objects are already stored as functions,
as.function.polynom is rarely needed and may be replaced by
unclass. An explicit call to as.function.polynom,
however, will generate a slightly faster version of the function as an
unrooled loop, and does allow the user to specify a different name for
the formal argument to be used.
Since arithmetic on polynomials is provided, both of these
functions may be evaluated at a polynom object as well as a
numeric argument.
Value
An R function implementing the evaluation.
Author(s)
Bill Venables
References
None
Examples
x <- polynom()
H <- polylist(polynom(1), x)
for(j in 2:5)
H[[j+1]] <- x*H[[j]] - (j-1)*H[[j-1]]
H5 <- as.function(H)
H5(-4:4)
H5(x+1)
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/as.function.polynom.Rd_%03d_medium.png", width=480, height=480)
> ### Name: as.function.polynom
> ### Title: Coerce polynom or polylist objects to function.
> ### Aliases: as.function.polynom as.function.polylist
> ### Keywords: symbolmath
>
> ### ** Examples
>
> x <- polynom()
> H <- polylist(polynom(1), x)
> for(j in 2:5)
+ H[[j+1]] <- x*H[[j]] - (j-1)*H[[j-1]]
> H5 <- as.function(H)
> H5(-4:4)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 -4 15 -52 163 -444
[2,] 1 -3 8 -18 30 -18
[3,] 1 -2 3 -2 -5 18
[4,] 1 -1 0 2 -2 -6
[5,] 1 0 -1 0 3 0
[6,] 1 1 0 -2 -2 6
[7,] 1 2 3 2 -5 -18
[8,] 1 3 8 18 30 18
[9,] 1 4 15 52 163 444
> H5(x+1)
[[1]]
1
[[2]]
1 + x
[[3]]
2*x + x^2
[[4]]
-2 + 3*x^2 + x^3
[[5]]
-2 - 8*x + 4*x^3 + x^4
[[6]]
6 - 10*x - 20*x^2 + 5*x^4 + x^5
>
>
>
>
>
> dev.off()
null device
1
>