Skip to article frontmatterSkip to article content

Interpolation using polynomials

from pylab import *

Polynomials are the simplest functions we can use since they require only basic arithmetic operations. They can provide a good approximation as shown by Weirstrass Theorem.

0.1Interpolation using monomials

Given N+1N+1 data (xi,yi)(x_i, y_i), i=0,1,,Ni=0,1,\ldots,N with yi=f(xi)y_i = f(x_i), we can try to find a polynomial of degree NN

p(x)=a0+a1x++aNxNp(x) = a_0 + a_1 x + \ldots + a_N x^N

that satisfies the interpolation conditions

p(xi)=yi,i=0,1,,Np(x_i) = y_i, \qquad i=0,1,\ldots, N

This is a linear system of N+1N+1 equations that can be written in matrix form

[1x0x02x0N1x1x12x1N1xNxN2xNN]V[a0a1aN]=[y0y1yN]\underbrace{\begin{bmatrix} 1 & x_0 & x_0^2 & \ldots & x_0^N \\ 1 & x_1 & x_1^2 & \ldots & x_1^N \\ \vdots & \vdots & \ldots & \vdots \\ 1 & x_N & x_N^2 & \ldots & x_N^N \end{bmatrix}}_{V} \begin{bmatrix} a_0 \\ a_1 \\ \vdots \\ a_N \end{bmatrix} = \begin{bmatrix} y_0 \\ y_1 \\ \vdots \\ y_N \end{bmatrix}

This has a unique solution if the Vandermonde matrix VV is non-singular. Since

detV=j=0Nk=j+1N(xkxj)\det V = \prod_{j=0}^N \prod_{k=j+1}^N (x_k - x_j)

we can solve the problem provided the points {xi}\{ x_i \} are distinct.

VV is non-singular. We can show this without computing the determinant. Assume that the {xi}\{ x_i \} are distinct. It is enough to show that the only solution of Va=0Va=0 is a=0a=0. Note that the set of N+1N+1 equations Va=0Va=0 is of the form

p(xi)=0,i=0,1,,Np(x_i) = 0, \qquad i=0,1,\ldots,N

which implies that p(x)p(x) has N+1N+1 distinct roots. But since pp is a polynomial of degree NN, this implies that p(x)0p(x) \equiv 0 and hence each ai=0a_i = 0.

0.2Condition number of VV

If we want to solve the interpolation problem by solving the matrix problem, then the condition number of the matrix becomes important. Matrices with large condition numbers cannot solved accurately on a computer due to blow-up in round-off errors.

0.3Lagrange interpolation

Lagrange interpolation provides the solution without having to solve a matrix problem. Define

πi(x)=(xx0)(xxi1)(xxi+1)(xxN)\pi_i(x) = (x-x_0) \ldots (x-x_{i-1})(x-x_{i+1})\ldots (x-x_N)

and

i(x)=πi(x)πi(xi)\ell_i(x) = \frac{\pi_i(x)}{\pi_i(x_i)}

Note that each i\ell_i is a polynomial of degree NN and i(xj)=δij\ell_i(x_j) = \delta_{ij}, i.e.,

i(xi)=0,i(xj)=0,ji\ell_i(x_i) = 0, \qquad \ell_i(x_j) = 0, \quad j \ne i

Then consider the polynomial of degree NN given by

pN(x)=j=0Nyjj(x)p_N(x) = \sum_{j=0}^N y_j \ell_j(x)

By construction this satisfies

pN(xi)=yi,i=0,1,,Np_N(x_i) = y_i, \qquad i=0,1,\ldots,N

and hence is the solution to the interpolation problem.

1Error in polynomial approximation

2Uniformly spaced points

Let us specialize the error estimate to the case of uniformly spaced points in the interval [a,b][a,b] with

xi=a+ih,0iN,h=baNx_i = a + i h, \qquad 0 \le i \le N, \qquad h = \frac{b-a}{N}

We have x0=ax_0 = a and xN=bx_N = b.

3Difficulty of polynomial interpolation

Do the polynomial approximations pNp_N converge to the true function ff as NN \to \infty ? The error formula seems to suggest so, due to the factor 1(N+1)!\frac{1}{(N+1)!} provided higher order derivatives of ff are bounded. On uniformly spaced points, we have seen the interpolants of cos(x)\cos(x) converge but those of the rational function 11+16x2\frac{1}{1+16x^2} do not. This must be related to the behaviour of the derivatives of these functions.

This is the general situation; for most functions, some higher order derivatives tend to grow as n!n!. Even for a polynomial pN(x)p_N(x), the derivatives grow in size until the NN’th one, which is aNN!a_N N!, after which they suddenly all become zero.

4Polynomial factor in error bound

The error of polynomial interpolation is given by

f(x)pN(x)=ωN(x)(N+1)!f(N+1)(ξ)f(x) - p_N(x) = \frac{\omega_N(x)}{(N+1)!} f^{(N+1)}(\xi)

where ξI(x0,x1,,xN,x)\xi \in I(x_0,x_1,\ldots,x_N,x) and

ωN(x)=(xx0)(xxN)\omega_N(x) = (x-x_0)\ldots(x-x_N)

Case N=1N=1. In case of linear interpolation

ω1(x)=(xx0)(xx1),h=x1x0\omega_1(x) = (x-x_0)(x-x_1), \qquad h = x_1 - x_0

Then

maxx0xx1ω1(x)=h24\max_{x_0 \le x \le x_1} |\omega_1(x)| = \frac{h^2}{4}

and the interpolation error bound is

maxx0xx1f(x)p1(x)h28maxx0xx1f(x)\max_{x_0 \le x \le x_1} |f(x) - p_1(x)| \le \frac{h^2}{8} \max_{x_0 \le x \le x_1}| f''(x)|

Case N=2N=2. To bound ω2(x)\omega_2(x) on [x0,x2][x_0,x_2], shift the origin to x1x_1 so that

ω2(x)=(xh)x(x+h)\omega_2(x) = (x-h)x(x+h)

Near the center of the data

maxx112hxx1+12hω2(x)=0.375h3\max_{x_1-\half h \le x \le x_1 + \half h} |\omega_2(x)| = 0.375 h^3

whereas on the whole interval

maxx0xx2ω2(x)=239h30.385h3\max_{x_0 \le x \le x_2} |\omega_2(x)| = \frac{2\sqrt{3}}{9}h^3 \approx 0.385 h^3

In this case, the error is of similar magnitude whether xx is near the center or near the edge.

Case N=3N=3. We can shift the nodes so that they are symmetric about the origin. Then

ω3(x)=(x294h2)(x214h2)\omega_3(x) = (x^2 - \frac{9}{4}h^2) (x^2 - \frac{1}{4}h^2)

and

maxx1xx2ω3(x)=916h40.56h4\max_{x_1 \le x \le x_2}|\omega_3(x)| = \frac{9}{16}h^4 \approx 0.56 h^4
maxx0xx3ω3(x)=h4\max_{x_0 \le x \le x_3}|\omega_3(x)| = h^4

In this case, the error near the endpoints can be twice as large as the error near the middle.

Case N>3N > 3. The behaviour exhibited for N=3N=3 is accentuated for larger degree. For N=6N=6,

maxx2xx4ω3(x)12.36h7,maxx0xx6ω3(x)95.8h7\max_{x_2 \le x \le x_4}|\omega_3(x)| \approx 12.36 h^7, \qquad \max_{x_0 \le x \le x_6}|\omega_3(x)| \approx 95.8 h^7

and the error near the ends can be almost 8 times that near the center.

5Distribution of data points

The error in polynomial interpolation is

f(x)pN(x)ωN(x)(N+1)!maxξf(N+1)(ξ)|f(x) - p_N(x)| \le \frac{|\omega_N(x)|}{(N+1)!} \max_{\xi} |f^{(N+1)}(\xi)|

where

ωN(x)=(xx0)(xx1)(xxN)\omega_N(x) = (x-x_0)(x-x_1) \ldots (x-x_N)

For a given function f(x)f(x), we cannot do anything about the derivative term in the error estimate. For uniformly spaced data points, ωN\omega_N has large value near the end points which is also where the Runge phenomenon is observed. But we can try to minimize the magnitude of ωN(x)\omega_N(x) by choosing a different set of nodes for interpolation. For the following discussion, let us assume that the xix_i are ordered and contained in the interval [1,+1][-1,+1].

Can we choose the nodes {xi}\{x_i\} so that

maxx[1,+1]ωN(x)\max_{x \in [-1,+1]} |\omega_N(x)|

is minimized ? We will show that

min{xi}maxx[1,+1]ωN(x)=2N\min_{\{x_i\}} \max_{x \in [-1,+1]} |\omega_N(x)| = 2^{-N}

and the minimum is achieved for following set of nodes

xi=cos(2(Ni)+12N+2π),i=0,1,,Nx_i = \cos\left( \frac{2(N-i)+1}{2N+2} \pi \right), \qquad i=0,1,\ldots,N

These are called Chebyshev points of first kind.

6Chebyshev polynomials

The Chebyshev polynomials are defined on the interval [1,+1][-1,+1] and the first few polynomials are

T0(x)=1T1(x)=x\begin{aligned} T_0(x) &=& 1 \\ T_1(x) &=& x \end{aligned}

The remaining polynomials can be defined by recursion

Tn+1(x)=2xTn(x)Tn1(x)T_{n+1}(x) = 2 x T_n(x) - T_{n-1}(x)

so that

T2(x)=2x21T3(x)=4x33xT4(x)=8x48x2+1\begin{aligned} T_2(x) =& 2x^2 - 1 \\ T_3(x) =& 4x^3 - 3x \\ T_4(x) =& 8x^4 - 8x^2 + 1 \end{aligned}

In Python, we can use function recursion to compute the Chebyshev polynomials.

def chebyshev(n, x):
    if n == 0:
        y = ones(len(x))
    elif n == 1:
        y = x.copy()
    else:
        y = 2*x*chebyshev(n-1,x) - chebyshev(n-2,x)
    return y

The first few of these are shown below.

N = 200
x = linspace(-1.0,1.0,N)
figure(figsize=(8,6))
for n in range(0,6):
    y = chebyshev(n,x)
    plot(x,y)
grid(True), xlabel('x'), ylabel('$T_n(x)$');
<Figure size 800x600 with 1 Axes>

We can write x[1,+1]x \in [-1,+1] in terms of an angle θ[0,π]\theta \in [0,\pi]

x=cosθx=\cos\theta

Properties of Chebyshev polynomials

  • Tn(x)T_n(x) is a polynomial of degree nn.

  • Tn(cosθ)=cos(nθ)T_n(\cos\theta) = \cos(n\theta). (Fourier cosine series)

  • Tn(x)=cos(ncos1(x))T_n(x) = \cos(n\cos^{-1}(x))

  • Tn(x)1|T_n(x)| \le 1

  • Extrema

    Tn(cosjπn)=(1)j,0jn T_n\left(\cos\frac{j\pi}{n}\right) = (-1)^j, \qquad 0 \le j \le n
  • Roots

    Tn(cos2j+12nπ)=0,0jn1 T_n\left( \cos \frac{2j+1}{2n}\pi \right) = 0, \qquad 0 \le j \le n-1

7Optimal nodes

Since ωN(x)\omega_N(x) is a monic polynomial of degree N+1N+1, we know from previous theorem that

max1x+1ωN(x)2N\max_{-1 \le x \le +1} |\omega_N(x)| \ge 2^{-N}

Can we choose the xix_i so that the minimum value of 2N2^{-N} is achieved ?

If xix_i are the N+1N+1 distinct roots of TN+1(x)T_{N+1}(x), then

ωN(x)=2NTN+1(x)\omega_N(x) = 2^{-N} T_{N+1}(x)

so that

max1x+1ωN(x)=2Nmax1x+1TN+1(x)=2N\max_{-1 \le x \le +1} |\omega_N(x)| = 2^{-N} \max_{-1 \le x \le +1} |T_{N+1}(x)| = 2^{-N}

The optimal nodes are given by

xi=cos(2i+12N+2π),0iNx_i = \cos\left( \frac{2i+1}{2N+2} \pi \right), \qquad 0 \le i \le N

In terms of θ variable, the spacing between these nodes is

θi+1θi=πN+1\theta_{i+1} - \theta_i = \frac{\pi}{N+1}