neville: Lagrange Interpolation Polynomials

View source: R/nevilles_algorithm.R

nevilleR Documentation

Lagrange Interpolation Polynomials

Description

Compute the Lagrange Interpolation Polynomial from a given set of x- and y-values, or, alterntively, compute the interpolated values at a set of given x-values. Two algorithms are provided, namely Neville's algorithm, or a more direct version based on the usual Lagrange formula. The latter is generally faster but the former can be more accurate numerically.

Usage

neville(x, y, x0 = polynomial())

lagrange(x, y, x0 = polynomial())

Arguments

x

A numeric vector of x-values

y

A numeric values of y-values corresponding to the x-values

x0

Either a polynomial object or a vector of x-values for which interpolated y-values are required.

Value

Either an interpolation polynomial object or a vector of interpolated y-values

Examples


set.seed(123)
x <- 1:5
y <- rnorm(x)
xout <- 0.5 + 1:4

p1 <- neville(x, y)
plot(p1, xlim = range(x), ylim = extendrange(y, f = 1), panel.first = grid())
points(x, y, col = 4)
points(xout, lagrange(x, y, xout), col = 2)

PolynomF documentation built on May 2, 2022, 9:07 a.m.