R: Functions to generate polynomials in several standard ways
poly.calc
R Documentation
Functions to generate polynomials in several standard ways
Description
poly.calc (alias poly.from.values) computes the Lagrange
interpolating polynomial. poly.from.zeros (alias
poly.from.roots) computes the monic polynomial with specified
zeros. poly.orth calculates polynomials orthogonal over a
discrete set of $x-$values, as done numerically by the standard R
function poly.
Usage
poly.calc(x, y, tol = sqrt(.Machine$double.eps), lab = dimnames(y)[[2]])
poly.from.values(x, y, tol = sqrt(.Machine$double.eps), lab = dimnames(y)[[2]])
poly.from.zeros(...)
poly.from.roots(...)
poly.orth(x, degree = length(unique(x)) - 1, norm = TRUE)
Arguments
x
A numeric vector of values for the polynomial variable.
y
A numeric vector or matrix specifying values for the polynomial.
tol
A numeric tolerance
lab
A character vector providing names for the polylist
of polynomials.
degree
The maximum degree for the orthogonal polynomials
required.
norm
Logical value. Should the polynomials be normalised to be
of length 1?)
...
Not presently used.
Details
Given a vector of distinct values x and a vector y of
the same length, poly.calc computes the Lagranging
intrepolating polynomial they define. If y is a matrix, its
row size must match the length of x and interpolating
polynomials are computed for all columns. In this case the value is a
polylist object.
poly.from.values is a complete alias for poly.calc.
The function poly.from.zeros computes the monic polynomial with
zeros as given by the arguments. The zeros may be specified either as
separate artuments or as a single numeric vector.
poly.from.roots is a complete alias for poly.from.zeros.
poly.orth calculates polynomials orthogonal with respect to the
uniform measure over a discrete set of $x-$values given by the
artument x. These are the polynomials for which the standard
function poly can be used to compute numerical values.
Value
A polynom object, or, in the case of poly.calc and
poly.orth, possibly a polylist object
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/poly.calc.Rd_%03d_medium.png", width=480, height=480)
> ### Name: poly.calc
> ### Title: Functions to generate polynomials in several standard ways
> ### Aliases: poly.calc poly.from.values poly.from.zeros poly.from.roots
> ### poly.orth
> ### Keywords: symbolmath
>
> ### ** Examples
>
> x <- polynom()
> H <- polylist(1, x)
> for(j in 2:10)
+ H[[j+1]] <- x*H[[j]] - (j-1)*H[[j-1]]
> Hf <- as.function(H)
> x0 <- -5:5
> y0 <- Hf(x0)
> J <- poly.from.values(x0, y0)
> all.equal(H[[11]], J[[11]])
[1] TRUE
>
> p1 <- poly.from.zeros(-3:2)
> p2 <- poly.from.zeros(0:4)
> p3 <- GCD(p1, p2)
> p4 <- LCM(p1, p2)
>
> solve(polylist(p1, p2, p3, p4))
[[1]]
[1] -3 -2 -1 0 1 2
[[2]]
[1] 0 1 2 3 4
[[3]]
[1] 0 1 2
[[4]]
[1] -3 -2 -1 0 1 2 3 4
>
> po <- poly.orth(-4:4, degree = 4)
> plot(po)
>
> round(crossprod(as.function(po)(-4:4)), 10)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 0
[2,] 0 1 0 0 0
[3,] 0 0 1 0 0
[4,] 0 0 0 1 0
[5,] 0 0 0 0 1
>
>
>
>
>
>
> dev.off()
null device
1
>