Last data update: 2014.03.03

R: Evaluating Polynomials
evalPolR Documentation

Evaluating Polynomials

Description

Function to evaluate polynomials in a numerical robust way using the Horner scheme

Usage

evalPol(x, beta)

Arguments

x

numerical values at which to evaluate polynomials, can be provided in a vector, matrix, array or data frame

beta

numerical vector containing the coefficient of the polynomial

Value

The result of evaluating the polynomial at the values in x, returned in the same dimension as x has.

Author(s)

Berwin A Turlach

Examples

beta <- c(1,2,1)

x <- 0:10
evalPol(x, beta)
str(evalPol(x, beta))

x <- cbind(0:10, 10:0)
evalPol(x, beta)
str(evalPol(x, beta))


x <- data.frame(x=0:10, y=10:0)
evalPol(x, beta)
str(evalPol(x, beta))

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(MonoPoly)
Loading required package: quadprog
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MonoPoly/evalPol.Rd_%03d_medium.png", width=480, height=480)
> ### Name: evalPol
> ### Title: Evaluating Polynomials
> ### Aliases: evalPol
> ### Keywords: utilities regression
> 
> ### ** Examples
> 
> beta <- c(1,2,1)
> 
> x <- 0:10
> evalPol(x, beta)
 [1]   1   4   9  16  25  36  49  64  81 100 121
> str(evalPol(x, beta))
 num [1:11] 1 4 9 16 25 36 49 64 81 100 ...
> 
> x <- cbind(0:10, 10:0)
> evalPol(x, beta)
      [,1] [,2]
 [1,]    1  121
 [2,]    4  100
 [3,]    9   81
 [4,]   16   64
 [5,]   25   49
 [6,]   36   36
 [7,]   49   25
 [8,]   64   16
 [9,]   81    9
[10,]  100    4
[11,]  121    1
> str(evalPol(x, beta))
 num [1:11, 1:2] 1 4 9 16 25 36 49 64 81 100 ...
> 
> 
> x <- data.frame(x=0:10, y=10:0)
> evalPol(x, beta)
     x   y
1    1 121
2    4 100
3    9  81
4   16  64
5   25  49
6   36  36
7   49  25
8   64  16
9   81   9
10 100   4
11 121   1
> str(evalPol(x, beta))
'data.frame':	11 obs. of  2 variables:
 $ x: num  1 4 9 16 25 36 49 64 81 100 ...
 $ y: num  121 100 81 64 49 36 25 16 9 4 ...
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>