[ top | up ]

Lagrange Interpolation Polynomial

Usage

poly.from.values(x, px, tol = sqrt(.Machine$double.eps))

Arguments

x x-values at which the polynomial has been evaluated. Duplicates are allowed, but see below.
px y-values for the polynomial for which an interpolation polynomial is required. If there are duplicate x-values, the corresponding y-values must also be identical (to within tol) or a warning is issued. Duplicates are then ignored and the first instance only is used.

If px is a matrix, the column size must be the same as the length of x, and a list of polynomials is returned got by using each column of px as a set of y-values in turn.

tol Error tolerance for judging (a) when y-values are close enough to be regarded as identical, and (b) when calculated coefficients are sufficiently close to zero in absolute value to allow them to be removed.

Description

Given a set of (x,y) points, construct the minimum degree polynomial passing through them.

The unvarnished Lagrange formula is used, which may present numerical difficulties on some occasions.

Value

The Lagrange interpolating polynomial.

See Also

poly.from.zeros, poly

Examples

x <- c(0,1,2,4)
px <- poly(x,3)
poly.from.values(x,px)
## $P1:
## -0.591607978309962 + 0.338061701891407*x 
## $P2:
## 0.564076074817766 - 1.1684432978368*x + 0.282038037408883*x^2 
## $P3:
## -0.286038776773678 + 3.11464445820227*x - 2.50283929676968*x^2 +  
## 0.437003686737563*x^3