Learn R Programming

PolynomF (version 2.0-8)

neville: 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())

Value

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

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.

Examples

Run this code

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)

Run the code above in your browser using DataLab