Learn R Programming

copula (version 0.999-18)

polynEval: Evaluate Polynomials

Description

Evaluate a univariate polynomial at x (typically a vector), that is, compute, for a given vector of coefficients coef, the polynomial coef[1] + coef[2]*x + ... + coef[p+1]*x^p.

Usage

polynEval(coef, x)

Arguments

coef

numeric vector. If a vector, x can be an array and the result matches x.

x

numeric vector or array.

Value

numeric vector or array, with the same dimensions as x, containing the polynomial values \(p(x)\).

Details

The stable Horner rule is used for evaluation.

Using the C code speeds up the already fast R code available in polyn.eval() in package sfsmisc.

See Also

For a much more sophisticated treatment of polynomials, use the polynom package (for example, evaluation can be done via predict.polynomial).

Examples

Run this code
# NOT RUN {
polynEval(c(1,-2,1), x = -2:7) # (x - 1)^2
polynEval(c(0, 24, -50, 35, -10, 1),
          x = matrix(0:5, 2,3)) # 5 zeros!
# }

Run the code above in your browser using DataLab