Skip to content

Interpolation & Polynomial Approximation

插值多项式 | Interpolating Polynomial

Lagrange插值多项式 | Lagrange Interpolating Polynomial

Inspired by 加权平均.

There exists and only exists a \(n\)th Lagrange interpolating polynomial (拉格朗日基函数)

\[ L_n(x) = \sum_{i=0}^{n}l_i(x)y_i = \begin{bmatrix} l_0(x) & l_1(x) &l_2(x) & \cdots & l_n(x) \end{bmatrix} \begin{bmatrix} y_0 \\ y_1 \\ \vdots \\ y_n \end{bmatrix} = \Phi_n(x)\vec{y} \]

such that for each pair of given points \((x_i, y_i)\), \(i = 0, 1,2,\cdots n\), we have \(y_i = L_n(x_i)\).

Here we can consider \(l_i(x)\) as a base of a linear space \(\mathcal{P}_n(x)\), and it can be displayed by natural base \(1, x, x^2, \cdots x^n\). To be more specific,

\[ l_i(x) = \prod_{j=0 \atop j \neq i }^{n}\frac{(x - x_i)}{(x_i-x_j)} \quad i=0,1,\cdots n \]

readers can prove the above \(n+1\) polynomials are linearly irrelevant.

Another form of \(l_i(x)\)

If we denote \(\omega(x)=\prod\limits_{k=0}^{n}(x-x_k)\), so the numerator of \(l_i(x)\) is

\[ \frac{\omega(x)}{x-x_i} \]

and its demunerator is

\[ \omega'(x)|_{x=x_i}=\sum_{j=0}^{n}\prod_{k=0 \atop k\neq j}^{n}(x-x_k)|_{x=x_i}=\prod_{k=0\atop k\neq i}^{n}(x_i-x_k) \]

so

\[ l_i(x)=\frac{\omega(x)}{(x-x_i)\omega'(x_i)} \]

which satisfies

\[ l_i(x_j)=\begin{cases}1,\quad &j=i,\\ 0,\quad &j\neq i.\end{cases} \]

Q1. Calculate the Lagrange polynomial that interpolates the following 3 points.

\(x_i\) 1 2 4
\(f(x_i)\) 8 1 5
\[ \begin{align*} p_2(x) &= \frac{(x-2)(x-4)}{(1-2)(1-4)}\times 8 + \frac{(x-1)(x-4)}{(2-1)(2-4)}\times 1 + \frac{(x-1)(x-2)}{(4-1)(4-2)}\times 5\\ &=\frac{8}{3}(x^2-6x+8)-\frac{1}{2}(x^2-5x+4)+\frac{5}{6}(x^2-3x+2)\\ &=3x^2-16x+21 \end{align*} \]

In fact, if we assume \(P_n(x) = \sum\limits_{i=0}^{n}a_ix^i\)(natural base), and to get the parameters \(\{a_i\}\) such that \(P_n(x_i) = y_i\), we have to solve the following linear system

\[ \begin{bmatrix} 1 & x_0 & x_0^2 &\cdots & x_0^n \\ 1 & x_1 & x_1^2 &\cdots & x_1^n \\ \vdots & \vdots & \vdots & &\vdots \\ 1 & x_n & x_n^2 &\cdots & x_n^n \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \\ \vdots \\ a_n \end{bmatrix}= \begin{bmatrix} y_0 \\ y_1 \\ \vdots \\ y_n \end{bmatrix} \]

which is a little tedious.

Neville方法 | Neville's Method

There is another way to express polynomial, which is also a weighted average.

An interpolation polynomial for a set of points \(A =\{x_0, x_1, \cdots x_n \}\) can be expressed by two polynomials that interpolate \(A\) \ \(\{ x_i\}\) and \(A\) \ \(\{ x_j\}\). That is,

\[ \begin{align*} P_{0,1,\cdots,n}(x) &= \frac{(x-x_i)P_{0,1,\cdots,i-1,i+1,\cdots,n}(x)-(x-x_j)P_{0,1,\cdots,j-1,j+1,\cdots,n}(x)}{(x_j-x_i)}\\ &=\frac{1}{(x_j-x_i)}\left|\begin{array}{cc} (x-x_i) & P_{0,1,\cdots,j-1,j+1,\cdots,n}(x) \\ (x-x_j) & P_{0,1,\cdots,i-1,i+1,\cdots,n}(x) \end{array}\right| \end{align*} \]

where \(P_{0,1,\cdots,i-1,i+1,\cdots,n}(x)\) and \(P_{0,1,\cdots,j-1,j+1,\cdots,n}(x)\) denotes the polynomial that interpolates \(A\) \ \(\{ x_i\}\) and \(A\) \ \(\{ x_j\}\) respectively.

For the first item, we have

\[ \begin{align*} P_{0,1}(x) &= \frac{(x-x_0)\times f(x_1)-(x-x_1)\times f(x_0)}{(x_1-x_0)}\\ &=\frac{1}{(x_1-x_0)}\left|\begin{array}{cc} (x-x_0) & f(x_0) \\ (x-x_1) & f(x_1) \end{array}\right| \end{align*} \]

Q2. Get the polynomial \(p_3(x)\) that interpolates the following 4 points and estimate \(f(5)\) by calculate \(p_3(5)\).

\(x_i\) 2 4 6 8
\(f(x_i)\) -8 0 8 64

It is a little tedious if we write the form of the polynomial and then substitute \(5\) in. It is more suitable to list a table.

\(x\) \(f(x)\) \(p_1(5)\) \(p_2(5)\) \(p_3(5)\)
2 -8
4 0 \(\frac{1}{(4-2)}\left|\begin{array}{cc} (5-2) & -8 \\ (5-4) & 0 \end{array}\right|=4\)
6 8 \(\frac{1}{(6-4)}\left|\begin{array}{cc} (5-4) & 0 \\ (5-6) & 8 \end{array}\right|=4\) \(\frac{1}{(6-2)}\left|\begin{array}{cc} (5-2) & 4 \\ (5-6) & 4 \end{array}\right|=4\)
8 64 \(\frac{1}{(8-6)}\left|\begin{array}{cc} (5-6) & -8 \\ (5-8) & 64 \end{array}\right|=-20\) \(\frac{1}{(8-4)}\left|\begin{array}{cc} (5-4) & 4 \\ (5-8) & -20 \end{array}\right|=-2\) \(\frac{1}{(8-2)}\left|\begin{array}{cc} (5-2) & 4 \\ (5-8) & -2 \end{array}\right|=1\)

Newton差商表达式 | Newton's Divided Difference Formula

If we rewrite the \(n\)th Lagrange polynomial \(P_n(x)\) into another form:

\[ P_n(x) = a_0+a_1(x-x_0)+a_2(x-x_0)(x-x_1)+\cdots+a_n(x-x_0)\cdots(x-x_n) \]

By letting \(x =x_0, x_1,\cdots, x_n\), we get

\[ \begin{align*} P_n(x_0) = & a_0\\ P_n(x_1) = & a_0 + a_1(x_1-x_0)\\ P_n(x_2) = & a_0+a_1(x_2-x_0)+a_2(x_2-x_0)(x_2-x_1)\\ &\vdots\\ P_n(x_n) = & a_0+a_1(x_n-x_0)+a_2(x_n-x_0)(x_n-x_1)+\\ &\cdots+a_n(x_n-x_0)\cdots(x_n-x_{n-1}) \end{align*} \]

Then we can define:

\[ \begin{align*} f_n[x_0] &\overset{\Delta}{=} f(x_0) = a_0\\ f_n[x_0, x_1] &\overset{\Delta}{=} \frac{f(x_1) - f(x_0)}{x_1-x_0} = a_1\\ f_n[x_0, x_1, x_2] &\overset{\Delta}{=} \frac{f[x_1,x_2]-f[x_0,x_1]}{x_2-x_0} \\&= \frac{\frac{f(x_2)-f(x_1)}{x_2-x_1}-\frac{f(x_1)-f(x_0)}{x_1-x_0} }{x_2-x_0} \\&= \frac{\frac{f(x_2)-f(x_0)-(f(x_1)-f(x_0))}{x_2-x_1}-a_1}{x_2-x_0} \\ &= \frac{\frac{f(x_2)-f(x_0)}{x_2-x_1} - \frac{a_1(x_1-x_0)}{x_2-x_1}-\frac{a_1(x_2-x_1)}{x_2-x_1}}{x_2-x_0} \\ &= \frac{\frac{f(x_2)-f(x_0)}{x_2-x_1} - \frac{a_1(x_2-x_0)}{x_2-x_1}}{x_2-x_0}\\ &= \frac{f(x_2)-a_0 - a_1(x_2-x_0)}{(x_2-x_0)(x_2-x_1)}=a_2\\ &\vdots\\ f[x_0,x_1,\cdots, x_n] &\overset{\Delta}{=} \frac{f[x_1,x_2,\cdots,x_n] - f[x_0,x_1,\cdots,x_{n-1}]}{x_n-x_0} = a_n \end{align*} \]

We can prove the above definition \(f[x_0,x_1\cdots,x_n]\), which is called divided difference, to be equal to \(a_n\) by induction.

We can also show that \(a_1\) is the coefficient of the highest item of polynomial of degree \(1\) that interpolates \(x_0,x_1\), and \(a_2\) is the coefficient of the highest item of polynomial of degree \(2\) that interpolates \(x_0,x_1,x_2\) ...

This iterative method is quite useful in determining the parameters of \(n\)th Lagrange polynomial.

\[ P_n(x) = f[x_0] + \sum_{i=1}^{n}\left(f[x_0,x_1,\cdots,x_i]\prod_{j=0}^{i-1}(x-x_j)\right) \]

The following relation gives a slightly quicker way to compute \(f[x_0,x_1,\cdots,x_n]\):

计算差商 | Calculating divided difference

\[ f[x_0,x_1,\cdots,x_n] = \sum_{k=0}^{n}\frac{f(x_k)}{\omega'_{n+1}(x_k)} \]

where

\[ \omega_{n+1}(x) = \prod_{i=0}^{n}(x-x_i),\quad \omega'_{n+1}(x_j) = \prod_{i=0 \atop i \neq j}^{n}(x_j-x_i) \]

We know from Lagrange polynomial of degree \(n\)

\[ P_n(x) = \sum_{i=0}^{n}f(x_i)\frac{\omega(x)}{(x-x_i)\omega'(x_i)} \]

where

\[ \omega(x) = \prod_{j=0}^n(x-x_j), \quad \omega'(x_i) = \prod_{j=0\atop j\neq i}^n(x_i-x_j) \]

So the divided difference equals to the coefficient of the highest item of \(P_n(x)\), and we are done.

Now solve Question 1 in the above part of the article.

\(x_i\) \(f(x_i)\) \(f[x_i,x_j]\) \(f[x_i,x_j,x_k]\)
1
2
4
8
1
5
-7
2
3

So the interpolating polynomial is

\[ P_2(x) = 8-7(x-1)+ 3(x-1)(x-2) \]

Some properties are the followings.

差商与微分均值的关系 | Relationship of DD & Mean Value Differentials

Suppose that \(f \in C^n[a, b]\) and \(x_0, x_1, \cdots, x_n\) are distinct numbers in \([a, b]\). Then a number \(\xi\) exists in \((a, b)\) with

\[ f[x_0,x_1\cdots,x_n] = \frac{f^{(n)}(\xi)}{n!} \]

Specifically, we denote \(a=\min\{x_i:i=0,1\cdots,n\}\) and \(b=\max\{x_i:i=0,1\cdots,n\}\)

It is like

\[ f[x_0,x_1] = \frac{f(x_1)-f(x_0)}{x_1-x_0} = f'(\xi) \]

but add \(n!\) to the denominator.

The collary can be quite simple.

Collary of the above

If \(f(x)\) is a polynomial of degree \(k\), \(k<n\), so the \(n\)th divided difference is \(0\).

插值误差分析 | Error Analysis of Interpolation

The following theorem gives the error bound.

拉格朗日基函数的余项 | The remainder of Lagrange interpolating polynomial

Suppose \(x_0, x_1, \cdots , x_n\) are distinct numbers in the interval \([a, b]\) and \(f \in C^{n+1}[a, b]\). Then, for each \(x \in [a, b]\), a number \(\xi(x)\) (generally unknown) between \(x_0, x_1, \cdots , x_n\), and hence in \((a, b)\), exists with

\[ f(x) = P(x) + \frac{f^{n+1}(\xi(x))}{(n+1)!}\prod_{i=0}^{n}(x - x_i) \]

where \(P(x)\) is the Lagrange interpolating polynomial.

Prove it.

  • Using a function
\[ g(t) = f(t) - P(t) - [f(x)-P(x)]\prod_{i=0}^{n}\frac{(t-x_i)}{x-x_i} \]

which is \(C^{n+1}[a, b]\). Here we see \(x\neq x_k\) is a constant for variable \(t\). Note that \(f(x_k)=0(k=0,1,\cdots n)\) and \(f(x)=0\) for \(x \in [a, b]\)(Readers can prove them by substituting in). We can see that \(n+1+1=n+2\) zero points here(\(x,x_0,\cdots, x_n\)).

  • Using generalized Rolle's Theorem: There exists \(\xi(x) \in [a, b]\) such that \(g^{n+1}(\xi(x))=0\)

And make \(n+1\) derivatives to \(g(t)\)(with respect to \(t\)), we have

\[ g^{(n+1)}(t)=f^{(n+1)}(t)-P^{(n+1)}(t)-\frac{(n+1)![f(x)-P(x)]}{\prod\limits_{i=0}^n (x-x_i)} \]

substitute in \(\xi\) we have

\[ 0=g^{(n+1)}(\xi)=f^{(n+1)}(\xi)- \frac{(n+1)![f(\xi)-P(\xi)]}{\prod\limits_{i=0}^n (x-x_i)} \]

cause \(P(x)\) is \(n\)th polynomial, so \(P^{(n+1)}(\xi)=0\). So solve for \(f(x)\) we have

\[ f(x)=P(x)+\frac{f^{n+1}(\xi(x))}{(n+1)!}\prod_{i=0}^{n}(x - x_i) \]

and we can get the result.

Or by using the relationship between divided difference and mean value differentials.

牛顿插值公式的余项 | The remainder of Newton's interpolating Formula

Suppose \(x_0, x_1, \cdots , x_n\) are distinct numbers in the interval \([a, b]\) and \(f \in C^{n+1}[a, b]\). Then, for each \(x \in [a, b]\), we have

\[ \begin{align*} f(x)=&f[x_0]+f[x_0,x_1](x-x_1)+\cdots\\ &+f[x_0,x_1,\cdots, x_n]\prod_{i=0}^{n-1}(x-x_i)\\ &+f[x_0,x_1,\cdots,x_n,x]\prod_{i=0}^n(x-x_i) \end{align*} \]

Similar to proof of Lagrange interpolation polynomial. We assume \(z\neq x_0,x_1,\cdots,x_n\), then consider \(n+1\)th polynomial \(Q(x)\) that interpolates these \(n+2\) points \(\{z,x_0,x_1,\cdots,x_n\}\), so we have

\[ Q(x)=f[x_0]+\sum_{i=1}^{n}\left(f[x_0,x_1,\cdots,x_i]\prod_{j=0}^{i-1}(x-x_j)\right)+f[x_0,x_1,\cdots,x_n,z]\prod_{i=0}^n(x-x_i) \]

which satisfies \(f(x_i)=Q(x_i)(i=0,1,\cdots,n)\) and \(f(z)=Q(z)\), the latter one gives

\[ f(z)= Q(z) = f[x_0]+\sum_{i=1}^{n}\left(f[x_0,x_1,\cdots,x_i]\prod_{j=0}^{i-1}(z-x_j)\right)+f[x_0,x_1,\cdots,x_n,z]\prod_{i=0}^n(z-x_i) \]

substitute \(z\) with \(x\) and we are done.

There is still one step left. For \(z=x_i\), divided difference \(f[x_0,x_1,\cdots,x_n,z]\) is not defined. So for \(x_i\), we consider a sequence \(\{y_k^{i}\}_{k=1}^\infty\), where \(y_k^i\neq x_i\) and \(\lim_{k\rightarrow \infty}y_k^i=x_i\). First we have the above theorem holds on \(y_k^i\), i.e.

\[ \begin{align*} f(y_k^i) &= f[x_0]+\sum_{i=1}^{n}\left(f[x_0,x_1,\cdots,x_i]\prod_{j=0}^{i-1}(y_k^i-x_j)\right)+f[x_0,x_1,\cdots,x_n,y_k^i]\prod_{i=0}^n(y_k^i-x_i)\\ &\overset{\Delta}{=}Q(y^i_k) + R(y^i_k) \end{align*} \]

we know that \(f(x)\) and \(Q(x)\)(\(n\)th polynomial) are continuous on \([a,b]\), so \(\lim_{k\rightarrow \infty}f(y_k^i)=f(x_i)\) and \(\lim_{k\rightarrow \infty}Q(y_k^i)=Q(x_i)=f(x_i)\), so

\[ \lim_{k\rightarrow \infty}R(y_k^i)=0 \]

we could define \(R(x_i)=0\) and the above equation still holds.

The above error item is useful in Numerical Integration.

Compared to the remainder of Taylor's extension

\[ R_n(x) = \frac{f^{n+1}(\xi(x))}{(n+1)!}(x-x_0)^{n+1} \]

Because \(\xi(x)\) is usually unknown, so we often use a number \(x' \in [a, b]\) such that

\[ |f^{n+1}(\xi(x))|\leq |f^{n+1}(x')| \]

等距插值 | Interpolation of Equidistant Points

In actual calculation in computer, we use difference to replace divided difference when we interpolate points with equal distance.

Definition of Difference on Equidistant Points

Difference of first order is defined by

\[ \Delta f(x_i)=f(x_{i+1})-f(x_i) \]

Difference of second order is defined by

\[ \begin{align*} \Delta^2 f(x_i)&=\Delta f(x_{i+1})-\Delta f(x_i)\\ &=f(x_{i+2})-2f(x_{i+1})+f(x_i) \end{align*} \]

By recursion, we define Difference of \(n\)th order

\[ \Delta^n f(x_i)=\Delta^{n-1}f(x_{i+1})-\Delta^{n-1}f(x_i) \]

By induction, it is easy to see that

\[ \begin{align*} \Delta^{n}f(x_i) = &f(x_{i+n})-nf(x_{i+n-1})+C^1_{n}f(x_{i+n-2})\\ +&\cdots+(-1)^{n-1}nf(x_{i+1})+(-1)^nf(x_i)\\ =&\sum_{k=0}^n(-1)^k C_n^kf(x_{i+k}). \end{align*} \]

We usually use the recursive method for computing.

In situation where points are equally distant, we have a relationship between divided difference and difference.

relationship between divided difference and difference

Under equidistant points, we have

\[ f[x_0,x_1,\cdots,x_n]=\frac{\Delta^{n}f(x_0)}{h^n n!} \]

where \(h\) is the distance between two adjacent points.

By induction.

Hermite多项式 | Hermite Polynomials

We want to consider the smoothness of interpolating polynomials, so we need to consider its derivatives, especially the first order derivative.

Definition of Osculating Polynomial

The osculating polynomial approximating \(f\) is the polynomial \(P(x)\) of least degree such that

\[ \frac{d^kP(x_i)}{dx^k} = \frac{d^kf(x_i)}{dx^k},\quad, \forall i = 0,1,\cdots, n, \forall k = 0,1,\cdots, m_i \]

Where \(n\) is the total number of sampling points and \(m_i\) is the degree of smoothness at point \(x_i\).

If \(m_i=1\) for all \(i=0,1,\cdots, n\), then the above polynomial is called Hermite Polynomial.

Composition of Hermite Polynomial

If \(f \in C^1[a, b]\) and \(x_0, \cdots , x_n \in [a, b]\) are distinct, the unique polynomial of least degree agreeing with \(f\) and \(f'\) at \(x_0,\cdots , x_n\) is the Hermite polynomial of degree at most \(2n + 1\) given by

\[ H_{2n+1}(x) = \sum_{j=0}^{n}f(x_j)H_{n,j}(x) + \sum_{j=0}^{n}f'(x_j)\hat{H}_{n,j}(x) \]

where, for \(L_{n, j}(x)\) denoting the \(j\)th Lagrange coefficient polynomial of degree \(n\), we have

\[ H_{n,j}(x) = [1-2(x-x_j)L'_{n,j}(x_j)]L^2_{n,j}(x),\quad \hat{H}_{n,j}(x) = (x-x_j)L^2_{n,j}(x) \]

The composition is usually a little tedious.

样条插值 | Cubic Spline Interpolation

We change \(\frac{d^kP(x_i)}{dx^k} = \frac{d^kf(x_i)}{dx^k}\) into equations between adjacent curves. Because we often do not know the derivatives of the point.

Define \(s(x)\) piece-wisely with \(s_i(x)\in [x_i,x_{i+1}]\)

\[ s_i(x)=a_i+b_ix+c_ix^2+d_ix^3, \quad i=0,1,\cdots,n-1 \]

which has 4 parameters to be determined. So the overall number of parameters to be determined is \(4n\). The condition they have to satisfy

\[ s_i(x_i)=f(x_i), s_i(x_{i+1})=f(x_{i+1}), i=0,1,\cdots,n-1 \quad \text{[$2n$ equations]} \]
\[ s'_i(x_{i})=s'_{i-1}(x_{i}),i=1,2,\cdots, n-1\quad \text{[$n-1$ equations]} \]
\[ s''_i(x_{i})=s''_{i-1}(x_{i}),i=1,2,\cdots, n-1\quad \text{[$n-1$ equations]} \]

So the above necessary condition gives \(4n-2\) equations while we have \(4n\) parameters to be determined. So we need to add another two equations for computing. There are many ways while the followings are usually seen.

Three possible dealings

(i) provide the derivatives of \(2\) endpoints, i.e. \(s'(a)=f'(a)\), \(s'(b)=f'(b)\), which is called D1 cubic spline or Clamped Cubic Spline.

(ii) provide the second derivatives of \(2\) endpoints, i.e. \(s''(a)=f''(a)\), \(s''(b)=f''(b)\), which is called D1 cubic spline. Specially, if \(s''(a)=s''(b)=0\), it is called Natural Spline.

(iii) take \(s(a)=f(a)\) or \(s(b)=f(b)\) out and provide extra \(3\) equations \(s(a)=s(b)\), \(s'(a)=s'(b)\), \(s''(a)=s''(b)\), which is called periodical cubic spline.

The solution for solving parameters by given condition.

Calculation of parameters

Consider \(s(x)\) on \([x_i,x_{i+1}]\), if we denote \(s''(x_i)=M_i\), then the overall equation becomes

\[ \mu_i M_{i-1}+2M_i+\lambda_i M_{i+1} = 6f[x_{i-1},x_i,x_{i+1}], \quad i=1,2,\cdots,n-1 \]

where

\[ \mu_i=\frac{x_i-x_{i-1}}{x_{i+1}-x_{i-1}}, \lambda_i=\frac{x_{i+1}-x_i}{x_{i+1}-x_{i-1}} \]

for \(i=0\) and \(i=n\) two situation, we deduce different equations for different condition.

(i) D1 cubic spline. we have

\[ \begin{cases} 2M_0+M_1=6f[x_0,x_0,x_1]\\ M_{n-2}+2M_{n-1}=6f[x_{n-2},x_{n-1}] \end{cases} \]

Q3. Interpolate the following points with natural cubic spline.

\(x_i\) 0 1 2
\(f(x_i)\) 1 2 6

Define \(s_0(x)=a_0+b_0x+c_0x^2+d_0x^3\) and \(s_1(x)=a_1+b_1(x-1)+c_1(x-1)^2+d_1(x-1)^3\), then

\[ \begin{cases} b_0+2c_0+3d_0=b_1 \quad &\text{derivative}\\ 2c_0+6d_0=2c_1\quad &\text{second derivative}\\ 2c_0=0 \quad &s''(a)=0\\ 2c_1+6d_1=0 \quad & s''(b)=0 \end{cases} \]

with condition that satisfies passing data points

\[ \begin{cases} a_0=1\\ a_0+b_0+c_0+d_0=2\\ a_1=2\\ a_1+b_1+c_1+d_1=6 \end{cases} \]

So represent all the parameters with \(d_1\) or \(d_0\), we get

\[ \begin{cases} a_0=1\\ b_0=\frac{1}{4}\\ c_0=0\\ d_0=\frac{3}{4} \end{cases} ,\quad \begin{cases} a_1=2\\ b_1=\frac{5}{2}\\ c_1=\frac{9}{4}\\ d_1=-\frac{3}{4}\\ \end{cases} \]