Neville’s Method of Polynomial Interpolation

[This article was first published on R – Aaron Schlegel, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Part 1 of 5 in the series Numerical Analysis

Neville’s method evaluates a polynomial that passes through a given set of x and y points for a particular x value using the Newton polynomial form. Neville’s method is similar to a now-defunct procedure named Aitken’s algorithm and is based on the divided differences recursion relation (“Neville’s Algorithm”, n.d).

It was stated before in a previous post on Lagrangian polynomial interpolation that there exists a Lagrange polynomial that passes through points y1,y2,,yk where each is a distinct integer and 0yin at corresponding x values x0,x1,x2,,xn. The k points y1,y2,,yk are denoted Py1,y2,,yk(x).

Neville’s Method

Neville’s method can be stated as follows:

Let a function f be defined at points x0,x1,,xk where xj and xi are two distinct members. For each k, there exists a Lagrange polynomial P that interpolates the function f at the k+1 points x0,x1,,xk. The kth Lagrange polynomial is defined as:

P(x)=(xxj)P0,1,,j1,j+1,,k(x)(xxi)P0,1,,i1,i+1,,k(x)(xixj)

The P0,1,,j1,j+1,,k and P0,1,,i1,i+1,,k are often denoted ˆQ and Q, respectively, for ease of notation.

P(x)=(xxj)ˆQ(x)(xxi)Q(x)(xixj)

The interpolating polynomials can thus be generated recursively, which we will see in the following example:

Neville’s Method Example

Consider the following table of x and corresponding y values.

x y
8.1 16.9446
8.3 17.56492
8.6 18.50515
8.7 18.82091

Suppose we are interested in interpolating a polynomial that passes through these points to approximate the resulting y value from an x value of 8.4.

We can construct the interpolating polynomial approximations using the function above:

Q1,1=(8.4x0)Q1,0(8.4x1)Q0,0x1x0=(8.48.1)(17.56492)(8.48.3)(16.9446)8.38.1=17.87508
Q2,1=(8.4x1)Q2,0(8.4x2)Q1,0(x2x1)=(8.48.3)(18.50515)(8.48.6)(17.56492)(8.68.3)=17.87833
Q3,1=(8.4x2)Q3,0(8.4x3)Q2,0(x3x2)=(8.48.6)(18.82091)(8.48.7)(18.50515)(8.78.6)=17.87363

The approximated values Q1,1=17.87508,Q2,1=17.87833,Q3,1=17.87363 are then used in the next iteration.

Q2,2=(8.4x0)Q2,1(8.4x2)Q1,1(x2x0)=(8.48.1)(17.87833)(8.48.6)(17.87508)(8.68.1)=17.87703
Q3,2=(8.4x1)Q3,1(8.4x3)Q2,1(x3x1)=(8.48.3)(17.87363)(8.48.7)(17.87833)(8.78.3)=17.877155

Then the final iteration yields the approximated y value for the given x value.

Q3,3=(8.4x0)Q3,2(8.4x3)Q2,2(x3x0)=(8.48.1)(17.877155)(8.48.7)(17.87703)(8.78.1)=17.8770925

Therefore 17.8770925 is the approximated value at the point 8.4.

Neville’s Method in R

The following function is an implementation of Neville’s method for interpolating and evaluating a polynomial.

poly.neville <- function(x, y, x0) {
  
  n <- length(x)
  q <- matrix(data = 0, n, n)
  q[,1] <- y
  
  for (i in 2:n) {
    for (j in i:n) {
      q[j,i] <- ((x0 - x[j-i+1]) * q[j,i-1] - (x0 - x[j]) * q[j-1,i-1]) / (x[j] - x[j-i+1])
    }
  }
  
  res <- list('Approximated value'=q[n,n], 'Neville iterations table'=q)
  return(res)
}

Let’s test this function to see if it reports the same result as what we found earlier.

x <- c(8.1, 8.3, 8.6, 8.7)
y <- c(16.9446, 17.56492, 18.50515, 18.82091)

poly.neville(x, y, 8.4)
## $`Approximated value`
## [1] 17.87709
## 
## $`Neville iterations table`
##          [,1]     [,2]     [,3]     [,4]
## [1,] 16.94460  0.00000  0.00000  0.00000
## [2,] 17.56492 17.87508  0.00000  0.00000
## [3,] 18.50515 17.87833 17.87703  0.00000
## [4,] 18.82091 17.87363 17.87716 17.87709

The approximated value is reported as 17.87709, the same value we calculated previously (minus a few decimal places). The function also outputs the iteration table that stores the intermediate results.

The pracma package contains the neville() function which also performs Neville’s method of polynomial interpolation and evaluation.

library(pracma)


neville(x, y, 8.4)
## [1] 17.87709

The neville() function reports the same approximated value that we found with our manual calculations and function.

References

Burden, R. L., & Faires, J. D. (2011). Numerical analysis (9th ed.). Boston, MA: Brooks/Cole, Cengage Learning.

Cheney, E. W., & Kincaid, D. (2013). Numerical mathematics and computing (6th ed.). Boston, MA: Brooks/Cole, Cengage Learning.

Neville’s algorithm. (2016, January 2). In Wikipedia, The Free Encyclopedia. From https://en.wikipedia.org/w/index.php?title=Neville%27s_algorithm&oldid=697870140

The post Neville’s Method of Polynomial Interpolation appeared first on Aaron Schlegel.

To leave a comment for the author, please follow the link and comment on their blog: R – Aaron Schlegel.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)