Learn R Programming

MonoPoly (version 0.2-8)

evalPol: 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.

Examples

Run this code
## The function is currently defined as
function (x, beta) 
{
    res <- 0
    for(bi in rev(beta))
      res <- res*x + bi
    res
  }

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))

Run the code above in your browser using DataLab