Numberical Analysis --- Interpolation & Polynomial Approximation





Welcome file

  If a function y=f(x)y=f(x) is too complicated for calculation or is even unknown, one way to approximate it is to first obtain its values y0=f(x0),...,xn=f(xn)y_0=f(x_0),...,x_n=f(x_n) at a sequence of points x0,...,xnx_0,...,x_n, and then construct a relatively simple approximating function g(x)f(x)g(x)\approx f(x).

  If g(x)g(x) satisfies that g(xi)=f(xi)g(x_i)=f(x_i) for all i=0,...,ni=0,...,n, it is called the interpolating function of f(x)f(x). The most commonly used interpolating functions are algebraic polynomials.

Interpolation and the Lagrange Polynomial

  Find a polynomial of degree nn, Pn(x)=a0+a1x+...+anxnP_n(x)=a_0+a_1x+...+a_nx^n, such that Pn(xi)=yiP_n(x_i)=y_i for all i=0,...,ni=0,...,n.

   n=1n=1: Given x0,x1;y0,y1x_0,x_1;y_0,y_1. Find P1(x)=a0+a1xP_1(x)=a_0+a_1x such that P1(x0)=y0P_1(x_0)=y_0 and P1(x1)=y1P_1(x_1)=y_1. P1(x)P_1(x) is the line function through the two given points (x0,y0)(x_0,y_0) and (x1,y1)(x_1,y_1).
P1(x)=y0+y1y0x1x0(xx0)=(xx1x0x1)y0+(xx0x1x0)y1=i=01L1,i(x)yi\Rightarrow \begin{aligned} P_1(x)&=y_0+\frac{y_1-y_0}{x_1-x_0}(x-x_0)\\ &=(\frac{x-x_1}{x_0-x_1})y_0+(\frac{x-x_0}{x_1-x_0})y_1\\ &=\sum\limits_{i=0}^1L_{1,i}(x)y_i\\ \end{aligned}

  n1n\geq 1: Find Ln,i(x)L_{n,i}(x) for i=0,...,ni=0,...,n such that Ln,i(xj)=δijL_{n,i}(x_j)=\delta_{ij}. Then let Pn(x)=i=0nLn,i(x)yiP_n(x)=\sum\limits_{i=0}^nL_{n,i}(x)y_i. Hence Pn(xi)=yiP_n(x_i)=y_i.

Each Ln,iL_{n,i} has nn roots x0,...,xnx_0,...,x_n.

The nn-th Lagrange interpolating polynomial:
Ln,i(x)=ji,0jn(xxj)(xixj)Pn(x)=i=0nLn,i(x)yiL_{n,i}(x)=\prod\limits_{j\neq i,0\leq j\leq n}\frac{(x-x_j)}{(x_i-x_j)}\Rightarrow P_n(x)=\sum\limits_{i=0}^nL_{n,i}(x)y_i

Theorem: If x0,...,xnx_0,...,x_n are n+1n+1 distinct numbers and ff is a function whose values are given at these numbers, then the nn-th Lagrange interpolating polynomial is unique.

Proof: If not… Then there exists two polynomials Pn(x)P_n(x) and Qn(x)Q_n(x) both satisfying the interpolating conditions.
D(x)=Pn(x)Qn(x) is a polynomial of degree n\Rightarrow D(x)=P_n(x)-Q_n(x)\text{ is a polynomial of degree }\leq n

Yet D(x)D(x) has n+1n+1 distinct roots x0,x1,...,xnx_0,x_1,...,x_n.

Note: The interpolating polynomial is NOT unique unless its degree is constrained to be no greater than nn. A counterexample is P(x)=Ln(x)+p(x)i=0n(xxi)P(x)=L_n(x)+p(x)\prod\limits_{i=0}^n(x-x_i) where p(x)p(x) can be a polynomial of any degree.

Analyze the Remainder

Suppose ax0<x1<...<xnba\leq x_0<x_1<...<x_n\leq b and fCn+1[a,b]f\in C^{n+1}[a,b]. Consider the truncation error Rn(x)=f(x)Pn(x)R_n(x)=f(x)-P_n(x)

Rn(x) has at least n+1 rootsRn(x)=K(x)i=0n(xxi)R_n(x)\text{ has at least }n+1\text{ roots}\Rightarrow R_n(x)=K(x)\prod\limits_{i=0}^n(x-x_i)

Fix any xxix\neq x_i for all i=0,...,ni=0,...,n. Define the function gg for tt in [a,b][a,b] by
g(t)=Rn(t)K(x)i=0n(txi)g(t)=R_n(t)-K(x)\prod\limits_{i=0}^n(t-x_i)
g(x)g(x) has n+2n+2 distinct roots x0,...,xn,xg(n+1)(ξx)=0,ξx(a,b)x_0,...,x_n,x\Rightarrow g^{(n+1)}(\xi_x)=0,\xi_x\in(a,b)
f(n+1)(ξx)Pn(n+1)(ξx)K(x)(n+1)!=Rn(n+1)(ξx)K(x)(n+1)!f^{(n+1)}(\xi_x)-P_n^{(n+1)}(\xi_x)-K(x)(n+1)!=R_n^{(n+1)}(\xi_x)-K(x)(n+1)!
K(x)=f(n+1)(ξx)(n+1)!Rn(x)=f(n+1)(ξx)(n+1)!i=0n(xxi)\Rightarrow K(x)=\frac{f^{(n+1)}(\xi_x)}{(n+1)!}\quad \Rightarrow R_n(x)=\frac{f^{(n+1)}(\xi_x)}{(n+1)!}\prod\limits_{i=0}^n(x-x_i)

Note:

  • Since in most of the case ξx\xi_x cannot be determined, we obtain the upper bound of f(n+1)f^{(n+1)} instead. That is, estimate an Mn+1M_{n+1} such that f(n+1)Mn+1|f^{(n+1)}|\leq M_{n+1} for all x(a,b)x\in(a,b) and take Mn+1(n+1)!i=0nxxi\frac{M_{n+1}}{(n+1)!}\prod\limits_{i=0}^n|x-x_i| as the upper bound of the total error.
  • The interpolating polynomial is accurate for any polynomial function ff with degree n\leq n since f(n+1)(x)0f^{(n+1)}(x)\equiv 0

Example: Suppose a table is to be prepared for the function f(x)=exf(x)=e^x for x[0,1]x\in[0,1]. Assume that each entry of the table is accurate up to 8 decimal places and the step size is hh. What should hh be for linear interpolation to given an absolute error of at most 10610^{-6}?

Solution: Suppose that [0,1][0,1] is partitioned into nn equal-spaced subintervals [x0,x1],[x1,x2],...,[xn1,xn][x_0,x_1],[x_1,x_2],...,[x_{n-1},x_n], and xx is in the interval [xk,xk+1][x_k,x_{k+1}]. Then the error estimation gives
f(x)P1(x)=f(2)(ξ)2!(xxk)(xxk+1)=eξ2(xkh)(x(k+1)h)e2×h24\begin{aligned} |f(x)-P_1(x)|&=\left|\frac{f^{(2)}(\xi)}{2!}(x-x_k)(x-x_{k+1})\right|\\ &=\left|\frac{e^\xi}{2}(x-kh)(x-(k+1)h)\right|\\ &\leq \frac{e}{2}\times \frac{h^2}{4}\\ \end{aligned}
eh28106h1.72×103\frac{eh^2}{8}\leq 10^{-6}\Rightarrow h\leq 1.72\times 10^{-3}

Simply take n=1000n=1000 and h=0.001h=0.001.

Example: Given sinπ6=12,sinπ4=12,sinπ3=32\sin \frac{\pi}{6}=\frac{1}{2},\sin \frac{\pi}{4}=\frac{1}{\sqrt{2}},\sin \frac{\pi}{3}=\frac{\sqrt{3}}{2}. Use the linear and the quadratic Lagrange polynomial of sinx\sin x to compute sin50\sin 50^\circ and then estimate the errors.

\textbf{Solution:} First use x0,x1x_0,x_1 and x1,x2x_1,x_2 to compute the linear interpolations.
Use x0=π6,x1=π4P1(x)=xπ/4π/6π/4×12+xπ/6π/4π/6×12\text{Use }x_0=\frac{\pi}{6},x_1=\frac{\pi}{4}\quad \Rightarrow P_1(x)=\frac{x-\pi/4}{\pi/6-\pi/4}\times \frac{1}{2}+\frac{x-\pi/6}{\pi/4-\pi/6}\times \frac{1}{\sqrt{2}}
sin50P1(5π18)0.77614Here f(x)=sinx,f(2)(ξx)=sinξx,ξx(π6,π3)\sin 50^\circ \approx P_1\left(\frac{5\pi}{18}\right)\approx0.77614\quad \text{Here }f(x)=\sin x,f^{(2)}(\xi_x)=-\sin \xi_x,\xi_x\in\left(\frac{\pi}{6},\frac{\pi}{3}\right)
and 12<sinξx<32,R1(x)=f(2)(ξx)2!(xπ6)(xπ4)\text{and }\frac{1}{2}<\sin \xi_x<\frac{\sqrt{3}}{2},R_1(x)=\frac{f^{(2)}(\xi_x)}{2!}(x-\frac{\pi}{6})(x-\frac{\pi}{4})
0.01319<R1(5π18)<0.00762\Rightarrow -0.01319<R_1\left(\frac{5\pi}{18}\right)<-0.00762
Error of extrapolation0.01001;Error of interpolation0.00596\text{Error of extrapolation}\approx-0.01001; \text{Error of interpolation}\approx0.00596
Now use x0,x1 and x2 to compute the quadratic interpolation.\text{Now use }x_0,x_1 \text{ and }x_2\text{ to compute the quadratic interpolation.}
P2(x)=(xπ/4)(xπ/3)(π/6π/4)(π/6π/3)×12+(xπ/6)(xπ/3)(π/4π/6)(π/4π/3)×12+(xπ/6)(xπ/4)(π/3π/6)(π/3π/4)×32\begin{aligned} P_2(x)&=\frac{(x-\pi/4)(x-\pi/3)}{(\pi/6-\pi/4)(\pi/6-\pi/3)}\times \frac{1}{2}+\frac{(x-\pi/6)(x-\pi/3)}{(\pi/4-\pi/6)(\pi/4-\pi/3)}\times \frac{1}{\sqrt{2}}\\&+\frac{(x-\pi/6)(x-\pi/4)}{(\pi/3-\pi/6)(\pi/3-\pi/4)}\times \frac{\sqrt{3}}{2}\\ \end{aligned}
R2(x)=cosξx3!(xπ6)(xπ4)(xπ3);12<cosξx<32R_2(x)=\frac{-\cos \xi_x}{3!}(x-\frac{\pi}{6})(x-\frac{\pi}{4})(x-\frac{\pi}{3});\frac{1}{2}<\cos \xi_x<\frac{\sqrt{3}}{2}
Error of the quadratic interpolation0.00061\text{Error of the quadratic interpolation}\approx 0.00061

Definition: Let ff be a function defined at x0,x1,...,xnx_0,x_1,...,x_n, and suppose that m1,...,mkm_1,...,m_k are kk distinct integers with 0min0\leq m_i\leq n for each ii. The Lagrange polynomial that agrees with f(x)f(x) at the kk points xm1,...,xmkx_{m_1},...,x_{m_k} denotes by Pm1,...,mk(x)P_{m_1,...,m_k}(x).

Theorem: Let ff be defined at x0,..,xkx_0,..,x_k, and let xix_i and xjx_j be two distinct numbers in this set. Then
P(x)=(xxj)P0,1,...,j1,j+1,...,k(x)(xxi)P0,1,...,i1,i+1,...,k(x)(xixj)P(x)=\frac{(x-x_j)P_{0,1,...,j-1,j+1,...,k}(x)-(x-x_i)P_{0,1,...,i-1,i+1,...,k}(x)}{(x_i-x_j)}
describes the kk-th Lagrange polynomial that interpolates ff at the k+1k+1 points x0,x1,...,xkx_0,x_1,...,x_k.

Proof: For any 0rk0\leq r\leq k and rir\neq i and jj, the two interpolating polynomials on the numerator are equal to f(xr)f(x_r) at xrx_r, so P(xr)=f(xr)P(x_r)=f(x_r). The first polynomials on the numerator equals f(xi)f(x_i) at xix_i, while the second term is zero, so P(xi)=f(xi)P(x_i)=f(x_i). Similarly P(xj)=f(xj)P(x_j)=f(x_j). The kk-th Lagrange polynomial that interpolates ff at the k+1k+1 points x0,x1,...,xkx_0,x_1,...,x_k is unique.

Divided Differences

The 1st1^{\text{st}} divided difference of ff w.r.t. xix_i and xjx_j:
f[xi,xj]=f(xi)f(xj)xixj(ij,xixj)f[x_i,x_j]=\frac{f(x_i)-f(x_j)}{x_i-x_j}\quad(i\neq j,x_i\neq x_j)

The 2nd2^{\text{nd}} divided difference of ff w.r.t. xi,xjx_i,x_j and xkx_k.
f[xi,xj,xk]=f[xi,xj]f[xj,xk]xixk(ik)f[x_i,x_j,x_k]=\frac{f[x_i,x_j]-f[x_j,x_k]}{x_i-x_k}\quad(i\neq k)

The k+1k+1st divided difference of ff w.r.t.x0,...,xk+1x_0,...,x_{k+1}:
f[x0,...,xk+1]=f[x0,x1,...,xk]f[x1,...,xk,xk+1]x0xk+1=f[x0,...,xk1,xk]f[x0,...,xk1,xk+1]xkxk+1\begin{aligned} f[x_0,...,x_{k+1}]&=\frac{f[x_0,x_1,...,x_k]-f[x_1,...,x_k,x_{k+1}]}{x_0-x_{k+1}}\\ &=\frac{f[x_0,...,x_{k-1},x_k]-f[x_0,...,x_{k-1},x_{k+1}]}{x_k-x_{k+1}}\\ \end{aligned}

As a matter of fact, f[x0,...,xk]=i=0kf(xi)ωk+1(xi)f[x_0,...,x_k]=\sum\limits_{i=0}^k\frac{f(x_i)}{\omega_{k+1}'(x_i)}

where ωk+1(x)=i=0k(xxi),ωk+1(xi)=0jk,ji(xixj)\omega_{k+1}(x)=\prod\limits_{i=0}^k(x-x_i),\omega_{k+1}'(x_i)=\prod\limits_{0\leq j\leq k,j\neq i}(x_i-x_j)

The value of f[x0,...,xk]f[x_0,...,x_k] is independent of the order of the numbers x0,...,xkx_0,...,x_k.

   Newton’s Interpolation
Nn(x)=a0+a1(xx0)+a2(xx0)(xx1)+...+an(xx0)...(xxn1)N_n(x)=a_0+a_1(x-x_0)+a_2(x-x_0)(x-x_1)+...+a_n(x-x_0)...(x-x_{n-1})
{f(x)=f(x0)+(xx0)f[x,x0]f[x,x0]=f[x0,x1]+(xx1)f[x,x0,x1]......f[x,x0,...,xn1]=f[x0,...,xn]+(xxn)f[x,x0,...,xn]\begin{cases} f(x)=f(x_0)+(x-x_0)f[x,x_0]\\ f[x,x_0]=f[x_0,x_1]+(x-x_1)f[x,x_0,x_1]\\ ......\\ f[x,x_0,...,x_{n-1}]=f[x_0,...,x_n]+(x-x_n)f[x,x_0,...,x_n]\\ \end{cases}
f(x)=f(x0)+f[x0,x1](xx0)+f[x0,x1,x2](xx0)(xx1)+...+f[x0,...,xn](xx0)...(xxn1)+f[x,x0,...,xn](xx0)...(xxn1)(xxn)=Nn(x)+Rn(x)\Rightarrow \begin{aligned} f(x)&=f(x_0)+f[x_0,x_1](x-x_0)+f[x_0,x_1,x_2](x-x_0)(x-x_1)+...\\ &+f[x_0,...,x_n](x-x_0)...(x-x_{n-1})\\ &+f[x,x_0,...,x_n](x-x_0)...(x-x_{n-1})(x-x_n)\\ &=N_n(x)+R_n(x)\\ \end{aligned}
ai=f[x0,...,xi]a_i=f[x_0,...,x_i]

Note:

  • Since the nn-th interpolating polynomial is unique, Nn(x)=Pn(x)N_n(x)=P_n(x).
  • They must have the same truncation error. That is,
    f[x,x0,...,xn]ωk+1(x)=f(n+1)(ξx)(n+1)!ωk+1(x)f[x,x_0,...,x_n]\omega_{k+1}(x)=\frac{f^{(n+1)}(\xi_x)}{(n+1)!}\omega_{k+1}(x)
    f[x0,...,xk]=f(k)(ξ)k!,ξ(xmin,xmax)\Rightarrow f[x_0,...,x_k]=\frac{f^{(k)}(\xi)}{k!},\xi\in(x_{\text{min}},x_{\text{max}})

   Formulae with Equal Spacing

If the points are equally spaced:xi=x0+ih(i=0,...,n)x_i=x_0+ih\quad(i=0,...,n)

forward difference:
Δfi=fi+1fi\Delta f_i=f_{i+1}-f_i
Δkfi=Δ(Δk1fi)=Δk1fi+1Δk1fi\Delta^kf_i=\Delta(\Delta^{k-1}f_i)=\Delta^{k-1}f_{i+1}-\Delta^{k-1}f_i

backward difference:
fi=fifi1\nabla f_i=f_i-f_{i-1}
kfi=k1fik1fi1\nabla^kf_i=\nabla^{k-1}f_i-\nabla^{k-1}f_{i-1}

centered difference:
δkfi=δk1fi+12δk1fi12\delta^kf_i=\delta^{k-1}f_{i+\frac{1}{2}}-\delta^{k-1}f_{i-\frac{1}{2}}
where fi±12=f(xi±h2)\text{where }f_{i\pm \frac{1}{2}}=f(x_i\pm \frac{h}{2})

  Some important properties

  1. Linearity:Δ(af(x)+bg(x))=aΔf+bΔg\Delta(af(x)+bg(x))=a\Delta f+b\Delta g

  2. If f(x)f(x) is a polynomial of degree mm, then Δkf(x)(0km)\Delta^kf(x)(0\leq k\leq m) is a polynomial of degree mkm-k and Δkf(x)=0(k>m)\Delta^kf(x)=0\quad (k>m)

  3. The values of the differences can be obtained from the function
    Δnfk=j=0n(1)jCnjfn+kjnfk=j=0n(1)njCnjfk+jn\Delta^nf_k=\sum\limits_{j=0}^n(-1)^jC_n^jf_{n+k-j}\quad \nabla^nf_k=\sum\limits_{j=0}^n(-1)^{n-j}C_n^jf_{k+j-n}

  4. And vice-versa fn+k=j=0nCnjΔjfkf_{n+k}=\sum\limits_{j=0}^nC_n^j\Delta^jf_k

  5. f[x0,...,xk]=Δkf0k!hk,f[xn,xn1,...,xnk]=kfkk!hkf[x_0,...,x_k]=\frac{\Delta^kf_0}{k!h^k},f[x_n,x_{n-1},...,x_{n-k}]=\frac{\nabla^kf_k}{k!h^k}
    From Rnf(k)(ξ)=Δkf0hk\text{From }R_n\Rightarrow f^{(k)}(\xi)=\frac{\Delta^kf_0}{h^k}

   Newton’s Formulae
Nn(x)=f(x0)+f[x0,x1](xx0)+...+f[x0,...,xn](xx0)...(xxn1)N_n(x)=f(x_0)+f[x_0,x_1](x-x_0)+...+f[x_0,...,x_n](x-x_0)...(x-x_{n-1})

   Newton’s forward-difference formula

Let x=x0+thx=x_0+th, then Nn(x)=Nn(x0+th)=k=0nCtkΔkf(x0)N_n(x)=N_n(x_0+th)=\sum\limits_{k=0}^nC_t^k\Delta^kf(x_0)
Rn(x)=f(n+1)(ξ)(n+1)!t(t1)...(tn)hn+1,ξ(x0,xn)R_n(x)=\frac{f^{(n+1)}(\xi)}{(n+1)!}t(t-1)...(t-n)h^{n+1},\xi\in(x_0,x_n)

   Newton’s backward-difference formula

Reverse the order of the points
Nn(x)=f(xn)+f[xn,xn1](xxn)+...+f[xn,...,x0](xxn)...(xx1)N_n(x)=f(x_n)+f[x_n,x_{n-1}](x-x_n)+...+f[x_n,...,x_0](x-x_n)...(x-x_1)

Let x=xn+thx=x_n+th, then Nn(x)=Nn(xn+th)=k=0n(1)kCtkkf(xn)N_n(x)=N_n(x_n+th)=\sum\limits_{k=0}^n(-1)^kC_{-t}^k\nabla^kf(x_n)

Hermite Interpolation

Find the osculating polynomial P(x)P(x) such that P(xi)=f(xi),P(xi)=f(xi),...,P(mi)(xi)=f(mi)(xi)P(x_i)=f(x_i),P'(x_i)=f'(x_i),...,P^{(m-i)}(x_i)=f^{(m-i)}(x_i) for all i=0,1,...,ni=0,1,...,n.

Note:

  • Given NN conditions (and hence NN equations), a polynomial of degree N1N-1 can be determined.
  • The osculating polynomial that agrees with ff and all its derivatives of order m0\leq m_0 at one point x0x_0 is just the Taylor polynomial
    P(x)=f(x0)+f(x0)(xx0)+...+f(m0)m0!(xx0)x0P(x)=f(x_0)+f'(x_0)(x-x_0)+...+\frac{f^{(m_0)}}{m_0!}(x-x_0)^{x_0}
    with remainder Rn(x)=f(x)φ(x)=f(m0+1)(ξ)(m0+1)!(xx0)m0+1R_n(x)=f(x)-\varphi(x)=\frac{f^{(m_0+1)}(\xi)}{(m_0+1)!}(x-x_0)^{m_0+1}
  • The case when mi=1m_i=1 for each i=0,1,...,ni=0,1,...,n gives the Hermite polynomials.

Example: Suppose x0x1x2x_0\neq x_1\neq x_2. Given f(x0),f(x1),f(x2)f(x_0),f(x_1),f(x_2) and f(x1)f'(x_1), find the polynomial P(x)P(x) such that P(xi)=f(xi),i=0,1,2P(x_i)=f(x_i),i=0,1,2, and P(x1)=f(x1)P'(x_1)=f'(x_1). Analyze the errors.

Solution: First of all, the degree of P(x)P(x) must be 3. Similar to Lagrange polynomials, we may assume the form of Hermite polynomial as:
P3(x)=i=02f(xi)hi(x)+f(x1)h1^(x)P_3(x)=\sum\limits_{i=0}^2f(x_i)h_i(x)+f'(x_1)\hat{h_1}(x)
where hi(xj)=δij,hi(x1)=0,h1^(xi)=0,h1^(x1)=1h_i(x_j)=\delta_{ij},h_i'(x_1)=0,\hat{h_1}(x_i)=0,\hat{h_1'}(x_1)=1

h0(x)h_0(x): Has roots x1,x2x_1,x_2, and h0(x1)=0x1h_0'(x_1)=0\Rightarrow x_1 is a multiple root.
{h0(x)=C0(xx1)2(xx2)h0(x0)=1C0h0(x)=(xx1)2(xx2)(x0x1)2(x0x2)\begin{cases} h_0(x)=C_0(x-x_1)^2(x-x_2)\\ h_0(x_0)=1\Rightarrow C_0\\ \end{cases}\Rightarrow h_0(x)=\frac{(x-x_1)^2(x-x_2)}{(x_0-x_1)^2(x_0-x_2)}

h2(x)h_2(x): Similar to h0(x)h_0(x).

h1(x)h_1(x): Has roots x0,x2h1(x)=(Ax+B)(xx0)(xx2)x_0,x_2\Rightarrow h_1(x)=(Ax+B)(x-x_0)(x-x_2). AA and BB can be solved with h1(x1)=1h_1(x_1)=1 and h1(x1)=0h_1'(x_1)=0.

h1^(x)\hat{h_1}(x): Has roots x0,x1,x2h1^(x)=C1(xx0)(xx1)(xx2)x_0,x_1,x_2\Rightarrow\hat{h_1}(x)=C_1(x-x_0)(x-x_1)(x-x_2). h1^(x1)=1C1\hat{h_1'}(x_1)=1\Rightarrow C_1 can be solved.

In general, given x0,...,xn;y0,...,ynx_0,...,x_n;y_0,...,y_n and y0,...,yny_0',...,y_n'. The Hermite polynomial H2n+1(x)H_{2n+1}(x) satisfies H2n+1(xi)=yiH_{2n+1}(x_i)=y_i and H2n+1(xi)=yiH_{2n+1}'(x_i)=y_i' for all ii.

Solution: Let H2n+1(x)=i=0nyihi(x)+i=0nyihi^(x)H_{2n+1}(x)=\sum\limits_{i=0}^ny_ih_i(x)+\sum\limits_{i=0}^ny_i'\hat{h_i}(x) where hi(xj)=δij,hi(xj)=0,hi^(xj)=0,hi^(xj)=δijh_i(x_j)=\delta_{ij},h_i'(x_j)=0,\hat{h_i}(x_j)=0,\hat{h_i'}(x_j)=\delta_{ij}.

hi(x)h_i(x): x0,...,xi^,...,xnx_0,...,\hat{x_i},...,x_n are all roots with multiplicity 2
hi(x)=(Aix+Bi)Ln,i2(x)\Rightarrow h_i(x)=(A_ix+B_i)L_{n,i}^2(x)
AiA_i and BiB_i can be solved by hi(xj)=1h_i(x_j)=1 and hi(xi)=0h_i'(x_i)=0
hi(x)=[12Ln,i(xi)(xxi)]Ln,i2(x)\Rightarrow h_i(x)=[1-2L_{n,i}'(x_i)(x-x_i)]L_{n,i}^2(x)

hi^(x)\hat{h_i}(x): All the roots x0,...,xnx_0,...,x_n have multiplicity 2 except xix_i\Rightarrow
{hi^(x)=Ci(xxi)Ln,i2(x)hi^(x)=1Ci=1hi^(x)=(xxi)Ln,i2(x)\begin{cases} \hat{h_i}(x)=C_i(x-x_i)L_{n,i}^2(x)\\ \hat{h_i'}(x)=1\Rightarrow C_i=1\\ \end{cases}\Rightarrow \hat{h_i}(x)=(x-x_i)L_{n,i}^2(x)
If a=x0<x1<...<xn=b,fC2n[a,b]a=x_0<x_1<...<x_n=b,f\in C^{2n}[a,b], then
Rn(x)=f(2n+2)(ξX)(2n+2)![i=0n(xxi)]2R_n(x)=\frac{f^{(2n+2)}(\xi_X)}{(2n+2)!}\left[\prod\limits_{i=0}^n(x-x_i)\right]^2

Cubic Spline Interpolation

  Piecewise linear interpolation

Approximate f(x)f(x) by linear polynomials on each subinterval [xi,xi+1][x_i,x_{i+1}]:
f(x)P1(x)=xxi+1xixi+1yi+xxixi+1xiyi+1 for x[xi,xi+1]f(x)\approx P_1(x)=\frac{x-x_{i+1}}{x_i-x_{i+1}}y_i+\frac{x-x_i}{x_{i+1}-x_i}y_{i+1}\text{ for }x\in[x_i,x_{i+1}]
Let h=maxxi+1xih=\max |x_{i+1}-x_i|. Then P1h(x)f(x)P_1^h(x)\to f(x) as h0h\to 0.

  Hermite piecewise polynomials

Given x0,..,xn;y0,...,yn;y0,...,ynx_0,..,x_n;y_0,...,y_n;y_0',...,y_n' Construct the Hermite polynomial of degree 3 with yy and yy' on the two endpoints of [xi,xi+1][x_i,x_{i+1}].

   Cubic Spline

Definition: Given a function ff defined on [a,b][a,b] and a set of nodes a=x0<x1<...<xn=ba=x_0<x_1<...<x_n=b, a cubic spline interpolant SS for ff is a function that satisfies the following conditions:

a. S(x)S(x) is a cubic polynomial, denoted Si(x)S_i(x), on the subinterval [xi,xi+1][x_i,x_{i+1}] for each i=0,1,...,n1i=0,1,...,n-1;

b. S(xi)=f(xi)S(x_i)=f(x_i) for each i=0,1,..,ni=0,1,..,n;

c. Si+1(xi+1)=Si(xi+1)S_{i+1}(x_{i+1})=S_i(x_{i+1}) for each i=0,1,...,n2i=0,1,...,n-2;

d. Si+1(xi+1)=Si(xi+1)S'_{i+1}(x_{i+1})=S_i'(x_{i+1}) for each i=0,1,...,n2i=0,1,...,n-2;

e. Si+1(xi+1)=Si(xi+1)S_{i+1}''(x_{i+1})=S_i''(x_{i+1}) for each i=0,1,...,n2i=0,1,...,n-2.

   Method of Bending Moment

Let hj=xjxj1h_j=x_j-x_{j-1} and S(x)=Sj(x)S(x)=S_j(x) for x[xj1,xj]x\in[x_{j-1},x_j]. Then Sj(x)S_j''(x) is a polynomial of degree 1, which can be determined by the values of ff on 2 nodes.

Assume Sj(xj1)=Mj1,Sj(xj)=MjS_j''(x_{j-1})=M_{j-1},S_j''(x_j)=M_j. Then for all x[xj1,xj]x\in[x_{j-1},x_j],
Sj(x)=Mj1xjxhj+Mjxxj1hjS_j''(x)=M_{j-1}\frac{x_j-x}{h_j}+ M_j\frac{x-x_{j-1}}{h_j}

Integrate Sj(x)S_j''(x) twice, we obtain Sj(x)S_j'(x) and Sj(x)S_j(x):
Sj(x)=Mj1(xjx)22hj+Mj1(xxj1)22hj+AjS_j'(x)=-M_{j-1}\frac{(x_j-x)^2}{2h_j}+M_{j-1}\frac{(x-x_{j-1})^2}{2h_j}+A_j
Sj(x)=Mj1(xjx)36hj+Mj(xxj1)36hj+Ajx+BjS_j(x)=M_{j-1}\frac{(x_j-x)^3}{6h_j}+M_j\frac{(x-x_{j-1})^3}{6h_j}+A_jx+B_j
Aj=yjyj1hjMjMj1hhjA_j=\frac{y_j-y_{j-1}}{h_j}-\frac{M_j-M_{j-1}}{h}h_j
Ajx+Bj=(yj1Mj16hj2)xjxhj+(yjMj6hj2)xxj1hjA_jx+B_j=\left(y_{j-1}-\frac{M_{j-1}}{6}h_j^2\right)\frac{x_j-x}{h_j}+\left(y_j-\frac{M_j}{6}h_j^2\right)\frac{x-x_{j-1}}{h_j}

Now solve for MjM_j: Since SS' is continuous at xjx_j
[xj1,xj]:Sj(x)=Mj1(xjx)22hj+Mj(xxj1)22hj+f[xj1,xj]MjMj16hj[x_{j-1},x_j]:S_j'(x)=-M_{j-1}\frac{(x_j-x)^2}{2h_j}+M_j\frac{(x-x_{j-1})^2}{2h_j}+f[x_{j-1},x_j]-\frac{M_j-M_{j-1}}{6}h_j
[xj,xj+1]:Sj+1(x)=Mj(xj+1x)22hj+1+Mj+1(xxj)22hj+1+f[xj,xj+1]Mj+1Mj6hj+1[x_j,x_{j+1}]:S_{j+1}'(x)=-M_j\frac{(x_{j+1}-x)^2}{2h_{j+1}}+M_{j+1}\frac{(x-x_j)^2}{2h_{j+1}}+f[x_j,x_{j+1}]-\frac{M_{j+1}-M_j}{6}h_{j+1}
From Sj(xj)=Sj+1(xj)S_j'(x_j)=S_{j+1}'(x_j), we can combine the coefficients for Mj1,MjM_{j-1},M_j, and Mj+1M_{j+1}. Define λj=hj+1hj+hj+1,μj=1λj\lambda_j=\frac{h_{j+1}}{h_j+h_{j+1}},\mu_j=1-\lambda_j, and gj=6hj+hj+1(f[xj,xj+1]f[xj1,xj])g_j=\frac{6}{h_j+h_{j+1}}(f[x_j,x_{j+1}]-f[x_{j-1},x_j])
μjMj1+2Mj+λjMj+1=gjfor 1jn1\Rightarrow \mu_jM_{j-1}+2M_j+\lambda_jM_{j+1}=g_j\quad \text{for }1\leq j\leq n-1
That is, we have n+1n+1 unknowns but only n1n-1 equations. Extra 2 boundary conditions are needed.

S(a)=y0,S(b)=yn/*Clamped boundary*/S'(a)=y_0',S'(b)=y_n'\quad \text{/*Clamped boundary*/}

[a,x1]:S1(x)=M0(x1x)22h1+M1(xa)22h1+f[x0,x1]M1M06h1[a,x_1]:S_1'(x)=-M_0\frac{(x_1-x)^2}{2h_1}+M_1\frac{(x-a)^2}{2h_1}+f[x_0,x_1]-\frac{M_1-M_0}{6}h_1

Similar for Sn(x)S_n'(x) on [xn1,b][x_{n-1},b]:
{2M0+M1=6h1(f[x0,x1]y0)=g0Mn1+2Mn=6hn(ynf[xn1,xn])=gn\Rightarrow \begin{cases} 2M_0+M_1=\frac{6}{h_1}(f[x_0,x_1]-y_0')=g_0\\ M_{n-1}+2M_n=\frac{6}{h_n}(y_n'-f[x_{n-1},x_n])=g_n\\ \end{cases}

S(a)=y0=M0,S(b)=yn=MnS''(a)=y_0''=M_0,S''(b)=y_n''=M_n
Then λ0=0,g0=2y0;μn=0,gn=2yn\lambda_0=0,g_0=2y_0'';\mu_n=0,g_n=2y_n''

The case when M0=Mn=0M_0=M_n=0 is called a free boundary, and when that occurs, the spline is called a Natural Spline.

Periodic Boundary: If ff is a periodic function, that is, yn=y0y_n=y_0 and S(a+)=S(b)M0=MnS'(a^+)=S'(b^-)\Rightarrow M_0=M_n

Note:

  • Cubic Spline can be uniquely determined by its boundary conditions as long as the coefficient matrix is strictly diagonally dominant.
  • If fC[a,b]f\in C[a,b] and maxhiminhiC<\frac{\max h_i}{\min h_i}\leq C<\infty. Then S(x)f(x)S(x)\to f(x) as maxhi0\max h_i\to 0. That is, the accuracy of approximation can be improved by adding more nodes without increasing the degree of the splines.

此博客中的热门博文

Numberical Analysis --- Numerical Differentiation and Integration

C++基础碎碎念