Skip to article frontmatterSkip to article content

6.7Newton interpolation

#%config InlineBackend.figure_format = 'svg'
from pylab import *

6.7.1The method

Consider N+1N+1 distinct points {x0,x1,,xN}\{x_0,x_1,\ldots,x_N\} at which data about a function is given. The Newton form of interpolation makes use of the basis functions

1,(xx0),(xx0)(xx1),,(xx0)(xx1)(xxN1)1, \quad (x-x_0), \quad (x-x_0)(x-x_1), \quad \ldots, \quad (x-x_0)(x-x_1)\ldots(x- x_{N-1})

so that the degree NN polynomial has the form

p(x)=    c0+c1(xx0)+c2(xx0)(xx1)+cN(xx0)(xxN1)\begin{align} p(x) &= \ \ \ \ c_0 \\ & \quad + c_1(x-x_0) \\ & \quad + c_2 (x-x_0)(x-x_1) \\ & \qquad \vdots \\ & \quad + c_N (x-x_0) \ldots(x-x_{N-1}) \end{align}

We now want to satisfy

p(xi)=fi=f(xi),0iNp(x_i) = f_i = f(x_i), \qquad 0 \le i \le N

The two practical questions are:

  1. How to determine the coefficients {ci}\{ c_i \} ?

  2. How to evaluate the resulting polynomial ?

The interpolation conditions are given by

f0=c0f1=c0+c1(x1x0)f2=c0+c1(x2x0)+c2(x2x0)(x2x1)fN=c0+c1(xNx0)++cN(xNx0)(xNxN1)\begin{aligned} f_0 &= c_0 \\ f_1 &= c_0 + c_1 (x_1 - x_0) \\ f_2 &= c_0 + c_1(x_2-x_0) + c_2(x_2-x_0)(x_2-x_1) \\ & \vdots \\ f_N &= c_0 + c_1 (x_N-x_0) + \ldots + c_N(x_N-x_0)\ldots(x_N-x_{N-1}) \end{aligned}

We have a matrix equation with a lower triangular matrix the non-singularity of the matrix is clear since the determinant is the product of the diagonal terms and this is non-zero since the points {xi}\{ x_i \} are distinct.

The triangular matrix can be solved recursively starting from the first equation; there is no need to invert the matrix. The coefficients {ci}\{ c_i \} can be computed in O(N2)O(N^2) operations but there is danger of overflow/ underflow errors if we do not do this carefully.

The triangular structure means that if we add a new data point (xN+1,fN+1)(x_{N+1},f_{N+1}), then the coefficients c0,c1,cNc_0, c_1, \cdots c_N do not change; we have to compute the additional coefficient cN+1c_{N+1}.

6.7.2Divided differences

Define zeroth divided difference

f[xi]=fi,i=0,1,,Nf[x_i] = f_i, \qquad i=0,1,\ldots,N

and the first divided difference

f[xi,xj]=f[xj]f[xi]xjxi,ijf[x_i,x_j] = \frac{f[x_j] - f[x_i]}{x_j - x_i}, \qquad i \ne j

The kk’th divided difference is defined recursively by

f[x0,x1,,xk]=f[x1,x2,,xk]f[x0,x1,,xk1]xkx0f[x_0,x_1,\ldots,x_k] = \frac{ f[x_1,x_2,\ldots,x_k] - f[x_0,x_1,\ldots,x_{k-1}]}{x_k - x_0}

We claim that the coefficient in Newton interpolant is

ck=f[x0,x1,,xk]c_k = f[x_0,x_1,\ldots,x_k]

We can compute the divided differences by constructing the following table

f[x0]f[x1]f[x0,x1]f[x2]f[x1,x2]f[x0,x1,x2]f[x3]f[x2,x3]f[x1,x2,x3]f[x0,x1,x2,x3]\begin{array}{llll} f[x_0] & & & \\ f[x_1] & f[x_0,x_1] & & \\ f[x_2] & f[x_1,x_2] & f[x_0,x_1,x_2] & \\ f[x_3] & f[x_2,x_3] & f[x_1,x_2,x_3] & f[x_0,x_1,x_2,x_3] \\ \vdots & \vdots & \vdots & \vdots \end{array}

The diagonal terms are the coefficients {ci}\{c_i\} of Newton interpolation. To compute the the diagonal terms, it is not necessary to store all the other terms in memory.

double x[N+1], f[N+1], c[N+1];
for(i=0; i<=N; ++i) c[i] = f[i];
for(j=1; j<=N; ++j)
   for(i=N; i>=j; --i)
      c[i] = (c[i] - c[i-1])/(x[i] - x[i-j]);

This requires N2N^2 additions and 12N2\frac{1}{2}N^2 divisions.

6.7.3Evaluation of polynomials

Suppose given xx we have to compute

p(x)=aNxN+aN1xN1++a1x+a0p(x) = a_N x^N + a_{N-1} x^{N-1} + \ldots + a_1 x + a_0

A direct term-by-term evaluation as in the above formula can suffer from overflow/ underflow error and the cost is also high. To see how to evaluate more efficiently, let us consider some simpler examples for quadratic

p=a2x2+a1x+a0=(a2x+a1)x+a0p = a_2 x^2 + a_1 x + a_0 = (a_2 x + a_1) x + a_0

and cubic polynomials,

p=a3x3+a2x2+a1x+a0=((a3x+a2)x+a1)x+a0p = a_3 x^3 + a_2 x^2 + a_1 x + a_0 = ((a_3 x + a_2) x + a_1) x + a_0

This suggests the following recursive algorithm called Horner’s method

p=aNp=px+aN1p=px+aN2p=px+a0\begin{aligned} p &= a_N \\ p &= p \cdot x + a_{N-1} \\ p &= p \cdot x + a_{N-2} \\ &\vdots \\ p &= p \cdot x + a_0 \end{aligned}

which gives p(x)p(x) at the end. This approach can be used for the Newton form also.

p=cNp=p(xxN1)+cN1p=p(xxN2)+cN2p=p(xx0)+c0\begin{aligned} p &= c_N \\ p &= p \cdot (x-x_{N-1}) + c_{N-1} \\ p &= p \cdot (x-x_{N-2}) + c_{N-2} \\ & \vdots \\ p &= p \cdot (x-x_0) + c_0 \end{aligned}

This requires 2N2N additions and NN multiplications so the cost is O(N)O(N).

double x[N+1], c[N+1];
double p = c[N];
for(int i=N-1; i<=0; --i)
{
   p = p * (x - x[i]) + c[i];
}

The direct term-by-term computation

double x[N+1], c[N+1];
double p = 0.0;
for(int i=0; i<=N; ++i)
{
   double tmp = 1.0;
   for(int j=0; j<i; ++j) tmp *= (x - x[j]);
   p += c[i] * tmp;
}

would require NN additions and

1+2++N=12N(N+1)1 + 2 + \ldots + N = \frac{1}{2}N(N+1)

multiplications for a total cost of O(N2)O(N^2) for each evaluation of p(x)p(x). This can be improved by a simple modification

double x[N+1], c[N+1];
double tmp = 1.0, p = 0.0;
for(int i=0; i<=N; ++i)
{
   p   += c[i] * tmp;
   tmp *= (x-x[i]);
}

6.7.4Proof of ck=f[x0,x1,,xk]c_k = f[x_0,x_1,\ldots,x_k]

The polynomial interpolating the data at {x0,x1,,xk}\{ x_0,x_1,\ldots,x_k \} is

pk(x)=c0+c1(xx0)+c2(xx0)(xx1)++ck(xx0)(xxk1)\begin{align} p_k(x) &= \quad c_0 \\ & \quad + c_1 (x-x_0) \\ & \quad + c_2 (x-x_0)(x-x_1) \\ & \quad + \ldots \\ & \quad + c_k (x-x_0)\ldots(x-x_{k-1}) \end{align}

Note that ckc_k depends on {x0,x1,,xk}\{x_0,x_1,\ldots,x_k\} so we indicate this dependence symbolically as

ck=f[x0,x1,,xk]c_k = f[x_0,x_1,\ldots,x_k]

We will show that this symbol satisfies the recursion relation for divided differences. Note that

ck= coefficient of xk in the polynomial pk(x)\textrm{$c_k = $ coefficient of $x^k$ in the polynomial $p_k(x)$}

Let us also write the Lagrange polynomial interpolating the same data as above. Define

ψk(x)=m=0k(xxm)=(xx0)(xx1)(xxk)\psi_k(x) = \prod_{m=0}^k (x - x_m) = (x-x_0)(x-x_1) \ldots (x-x_k)

so that

ψk(xi)=m=0,mik(xixm)=(xix0)(xixi1)(xixi+1)(xixk)\psi_k'(x_i) = \prod_{m=0,m \ne i}^k (x_i - x_m) = (x_i-x_0) \ldots (x_i - x_{i-1})(x_i-x_{i+1}) \ldots (x_i-x_k)

Then the Lagrange form can be written as

pk(x)=j=0kψk(x)(xxj)ψk(xj)f(xj)p_k(x) = \sum_{j=0}^k \frac{\psi_k(x)}{(x-x_j)\psi_k'(x_j)} f(x_j)

The coefficient of xkx^k in this form is

ck=f[x0,x1,,xk]=j=0kf(xj)ψk(xj)c_k = f[x_0,x_1,\ldots,x_k] = \sum_{j=0}^k \frac{f(x_j)}{\psi_k'(x_j)}

since the interpolating polynomial is unique.

Now, using above result, we can write a formula for f[x0,x1,,xk1]f[x_0,x_1,\ldots,x_{k-1}] but we have to knock off the factor (xjxk)(x_j-x_k) from ψk(xj)\psi_k'(x_j), so that

f[x0,x1,,xk1]=j=0k1f(xj)ψk(xj)(xjxk)=j=0kf(xj)ψk(xj)(xjxk)f[x_0,x_1,\ldots,x_{k-1}] = \sum_{j=0}^{k-1} \frac{f(x_j)}{\psi_k'(x_j)} (x_j-x_k) = \sum_{j=0}^k \frac{f(x_j)}{\psi_k'(x_j)} (x_j - x_k)

Similarly

f[x1,x2,,xk]=j=1kf(xj)ψk(xj)(xjx0)=j=0kf(xj)ψk(xj)(xjx0)f[x_1,x_2,\ldots,x_{k}] = \sum_{j=1}^{k} \frac{f(x_j)}{\psi_k'(x_j)} (x_j-x_0) = \sum_{j=0}^k \frac{f(x_j)}{\psi_k'(x_j)} (x_j - x_0)

Hence

f[x1,x2,,xk]f[x0,x1,,xk1]=j=0kf(xj)ψk(xj)(xkx0)=(xkx0)f[x0,x1,,xk]\begin{align*} f[x_1,x_2,\ldots,x_{k}] - f[x_0,x_1,\ldots,x_{k-1}] &= \sum_{j=0}^k \frac{f(x_j)} {\psi_k'(x_j)} (x_k - x_0) \\ &= (x_k - x_0) f[x_0,x_1,\ldots,x_k] \end{align*}

which is the recursion relation for divided differences.

6.7.5Interpolation error

The Newton form of interpolation to the data (xi,fi)(x_i,f_i), i=0,1,,Ni=0,1,\ldots,N is

pN(x)=f0+(xx0)f[x0,x1]+(xx0)(xx1)f[x0,x1,x2]++(xx0)(xxN1)f[x0,,xN]\begin{aligned} p_N(x) = f_0 & + (x-x_0)f[x_0,x_1] \\ & + (x-x_0)(x-x_1) f[x_0,x_1, x_2] \\ & + \ldots \\ & + (x-x_0) \ldots (x-x_{N-1}) f[x_0,\ldots,x_N] \end{aligned}

Let tRt \in \re be distinct from the nodes {x0,x1,,xN}\{x_0,x_1,\ldots,x_N\} but otherwise arbitrary. The polynomial interpolating f(x)f(x) at {x0,x1,,xN,t}\{x_0,x_1,\ldots,x_N,t\} is

pN+1(x)=pN(x)+(xx0)(xxN)f[x0,,xN,t]p_{N+1}(x) = p_N(x) + (x-x_0)\ldots (x-x_N) f[x_0,\ldots,x_N,t]

But pN+1(t)=f(t)p_{N+1}(t) = f(t) so that

f(t)=pN(t)+(tx0)(txN)f[x0,,xN,t]f(t) = p_N(t) + (t-x_0)\ldots (t-x_N) f[x_0,\ldots,x_N,t]

Since tt was arbitrary, we could call it xx. Then the error is

f(x)pN(x)=(xx0)(xxN)f[x0,,xN,x]f(x) - p_N(x) = (x-x_0)\ldots (x-x_N) f[x_0,\ldots,x_N,x]

Comparing this with the formula we have derived earlier, we conclude that

f[x0,,xN,x]=1(N+1)!f(N+1)(ξ),ξI(x0,,xN,x)f[x_0,\ldots,x_N,x] = \frac{1}{(N+1)!} f^{(N+1)}(\xi), \qquad \xi \in I(x_0,\ldots,x_N,x)

6.7.6Another proof of independence of order

We will show that f[x0,x1,,xN]f[x_0,x_1,\ldots,x_N] is independent of the order of the arguments. Let pN1(x)p_{N-1}(x) interpolate the data {x0,x1,,xN1}\{ x_0, x_1, \ldots, x_{N-1}\}. In Newton form

pN1(x)=f0+(xx0)f[x0,x1]+(xx0)(xx1)f[x0,x1,x2]++(xx0)(xxN2)f[x0,,xN1]\begin{aligned} p_{N-1}(x) = f_0 & + (x-x_0)f[x_0,x_1] \\ & + (x-x_0)(x-x_1) f[x_0,x_1, x_2] \\ & + \ldots \\ & + (x-x_0) \ldots (x-x_{N-2}) f[x_0,\ldots,x_{N-1}] \end{aligned}

Consider a random permutation

{xi0,xi1,,xiN1}\{ x_{i_0}, x_{i_1}, \ldots, x_{i_{N-1}} \}

and let QN1(x)Q_{N-1}(x) interpolate this data

QN1(x)=fi0+(xxi0)f[xi0,xi1]+(xxi0)(xxi1)f[xi0,xi1,xi2]++(xxi0)(xxiN2)f[xi0,,xiN1]\begin{aligned} Q_{N-1}(x) = f_{i_0} & + (x-x_{i_0})f[x_{i_0},x_{i_1}] \\ & + (x-x_{i_0})(x-x_{i_1}) f[x_{i_0},x_{i_1}, x_{i_2}] \\ & + \ldots \\ & + (x-x_{i_0}) \ldots (x-x_{i_{N-2}}) f[x_{i_0},\ldots,x_{i_{N-1}}] \end{aligned}

But these two polynomials are same QN1=PN1Q_{N-1} = P_{N-1} since they interpolate same data, and in particular the error at x=xNx=x_N is same

(xNx0)(xNxN1)f[x0,x1,,xN]=(xNxi0)(xNxiN1)f[xi0,xi1,,xN]\begin{align*} (x_N-x_0) \ldots(x_N - x_{N-1}) & f[x_0,x_1,\ldots,x_N] = \\ & (x_N-x_{i_0}) \ldots(x_N - x_{i_{N-1}}) f[x_{i_0},x_{i_1},\ldots,x_N] \end{align*}

Since the polynomial factors are same, we get

f[x0,x1,,xN]=f[xi0,xi1,,xN]f[x_0,x_1,\ldots,x_N] = f[x_{i_0},x_{i_1},\ldots,x_N]

We can repeat this proof by leaving out xN1,xN2,,x0x_{N-1}, x_{N-2}, \ldots, x_0 and then we obtain the complete proof.

6.7.7Forward difference operator

For h>0h > 0, define the forward difference

Δf(x)=f(x+h)f(x)\Delta f(x) = f(x+h) - f(x)

We will use uniformly spaced data at

xi=x0+ih,i=0,1,2,x_i = x_0 + ih, \qquad i=0,1,2,\ldots

Then

Δf(xi)=f(xi+h)f(xi)=f(xi+1)f(xi)=fi+1fi\Delta f(x_i) = f(x_i+h) - f(x_i) = f(x_{i+1}) - f(x_i) = f_{i+1} - f_i

or, in compact form

Δfi=fi+1fi\Delta f_i = f_{i+1} - f_i

For r0r \ge 0, define

Δr+1f(x)=Δrf(x+h)Δrf(x)\Delta^{r+1} f(x) = \Delta^r f(x+h) - \Delta^r f(x)

with

Δ0f(x)=f(x)\Delta^0 f(x) = f(x)

Δr+1f(x)\Delta^{r+1} f(x) is called the rr-th order forward difference of ff at xx.

6.7.8Newton form on uniform data

For uniformly spaced data, we can avoid the use of divided differences and write in terms of forward differences, which is more efficient since we avoid division, which is an expensive operation. Define

μ=xx0h\mu = \frac{x - x_0}{h}

Newton interpolation formula has factors of the form (xx0)(xxk)(x-x_0)\ldots(x-x_k). Since

xxj=(x0+μh)(x0+jh)=(μj)hx-x_j = (x_0 + \mu h) - (x_0 + jh) = (\mu-j) h

hence

(xx0)(xxk)=μ(μ1)(μk)hk+1(x-x_0)\ldots(x-x_k) = \mu(\mu-1)\ldots(\mu-k) h^{k+1}

Using previous lemma, we write divided difference in terms of forward differences

pn(x)=f0+μhΔf0h+μ(μ1)h2Δ2f02!h2++μ(μ1)(μn+1)hnΔnf0n!hn\begin{align} p_n(x) &= f_0 \\ & \quad + \mu h \frac{\Delta f_0}{h} \\ & \quad + \mu(\mu-1)h^2 \frac{\Delta^2 f_0}{2! h^2} \\ & \quad + \ldots \\ & \quad + \mu(\mu-1)\ldots(\mu-n+1)h^n \frac{\Delta^n f_0}{n! h^n} \end{align}

Define the binomial coefficients

(μk)=μ(μ1)(μk+1)k!,k>0(μ0)=1\begin{align} \binom{\mu}{k} &= \frac{\mu(\mu-1) \ldots (\mu-k+1)}{k!}, \qquad k > 0 \\ \binom{\mu}{0} &= 1 \end{align}

Then

pn(x)=j=0n(μj)Δjf0,μ=xx0hp_n(x) = \sum_{j=0}^n \binom{\mu}{j} \Delta^j f_0, \qquad \mu = \frac{x-x_0}{h}

This is the Newton forward difference form of the interpolating polynomial. A schematic of the computation is shown in Table 1.

Table 1:Forward differences

xix_ifif_iΔfi\Delta f_iΔ2fi\Delta^2 f_iΔ3fi\Delta^3 f_iΔ4fi\Delta^4 f_iΔ5fi\Delta^5 f_i
x0x_0f0f_0
Δf0\Delta f_0
x1x_1f1f_1Δ2f0\Delta^2 f_0
Δf1\Delta f_1Δ3f0\Delta^3 f_0
x2x_2f2f_2Δ2f1\Delta^2 f_1Δ4f0\Delta^4 f_0
Δf2\Delta f_2Δ3f1\Delta^3 f_1Δ5f0\Delta^5 f_0
x3x_3f3f_3Δ2f2\Delta^2 f_2Δ4f1\Delta^4 f_1
Δf3\Delta f_3Δ3f2\Delta^3 f_2
x4x_4f4f_4Δ2f3\Delta^2 f_3
Δf4\Delta f_4
x5x_5f5f_5

6.7.9Errors in data and forward differences

We can use a forward difference table to detect noise in physical data, as long as the noise is larger relative to the experimental error.

The divided differences make sense even if some of the arguments are equal. This can be seen by deriving an integral formula.

Note that τnRn\tau_n \subset \re^n. E.g., τ2\tau_2 is a right triangle with sides of length 1 along x,yx,y directions; τ3\tau_3 is the tetrahedron with sides of length 1 parallel to the coordinate axes. Moreover

volume(τn)=1n!\textrm{volume}(\tau_n) = \frac{1}{n!}

6.7.10Some properties of divided differences

  1. The divided difference of n+1n+1 points satisfies

    f[x0,,xn]=f(n)(ξ)n!,ξI[x0,x1,,xn]f[x_0,\ldots,x_n] = \frac{f^{(n)}(\xi)}{n!}, \qquad \xi \in I[x_0,x_1,\ldots,x_n]

    We obtained this by comparing the error of Newton interpolation with that of polynomial interpolation. Prove this result by induction. The Hermite-Gennochi formula relates the sames quantities in terms of an integral.

  2. If f(n)f^{(n)} is continuous in the interval I[x0,x1,,xn]I[x_0,x_1,\ldots,x_n], then f[x0,,xn]f[x_0,\ldots,x_n] is a continuous function of {x0,,xn}\{x_0, \ldots,x_n\}.

  3. From the Hermite-Gennochi formula, we see that the right hand side makes sense even if all the xjx_j are not distinct. If we take all arguments to be equal to xx, then

    f[x,x,,xn+1 arguments]=τnf(n)(x)dt1dtn=fn(x) volume(τn)=f(n)(x)n!\begin{aligned} f[\underbrace{x,x,\ldots,x}_{n+1 \textrm{ arguments}}] =& \int_{\tau_n} f^{(n)}(x) \ud t_1 \ldots \ud t_n \\ =& f^n(x) \textrm{ volume}(\tau_n) \\ =& \frac{f^{(n)}(x)}{n!} \end{aligned}
  4. Consider f[x0,,xn,x]f[x_0,\ldots,x_n,x] as a function of xx and differentiate this wrt xx. By definition of the derivative

    ddxf[x0,,xn,x]=limh0f[x0,,xn,x+h]f[x0,,xn,x]h=limh0f[x0,,xn,x+h]f[x,x0,,xn](x+h)x=limh0f[x,x0,,xn,x+h]=f[x,x0,,xn,x]=f[x0,,xn,x,x]\begin{aligned} \dd{}{x}f[x_0,\ldots,x_n,x] =& \lim_{h \to 0} \frac{f[x_0,\ldots,x_n,x+h] - f[x_0,\ldots,x_n,x]}{h} \\ =& \lim_{h \to 0} \frac{f[x_0,\ldots,x_n,x+h] - f[x,x_0,\ldots,x_n]}{(x+h) -x} \\ =& \lim_{h \to 0} f[x,x_0,\ldots,x_n,x+h] \\ =& f[x,x_0,\ldots,x_n,x] \\ =& f[x_0,\ldots,x_n,x,x] \end{aligned}

    The quantity on the right has n+3n+3 arguments and it is well defined if fCn+2f \in \cts^{n+2}.

References
  1. Atkinson, K. E. (2004). An Introduction to Numerical Analysis (2nd ed.). Wiley.