Skip to contents

Evaluate the polynomial whose coefficients are represented in coeff vector. The order of the coefficient is an increasing order, i.e., coeff[1] is a constant term, and coeff[2] is a coefficient of 1st degree term, etc. Evaluation is done using Horner's method.

Usage

eval_poly(coeff, x)

Arguments

coeff

A coefficient vector in increasing order of degrees; the first element is 0th degree, ..., and the last element is the largest degree of coefficients.

x

A numeric input vector.

Value

A vector of values of a polynomial whose coefficient is coeff.

Examples

## Evaluate a polynomial x^2 - 2x + 2 with x = 1, 2, 3.
## 0th, 1st, 2nd degree of coefficients
coeff <- c(2, -2, 1)
x <- c(1, 2, 3)
eval_poly(coeff, x)
#> [1] 1 2 5