Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Introduction to Numerical Methods/Interpolation

From Wikibooks, open books for an open world
<Introduction to Numerical Methods

Objectives

  • understand interpolation
  • derive Newton’s divided difference method of interpolation
  • derive Lagrangian method of interpolation
  • apply the interpolation methods to solve problems
  • find derivatives and integrals of discrete functions using interpolation

Resources

Interpolation

[edit |edit source]

Interpolation is the process of deriving a simple function from a set of discrete data points so that the function passes through all the given data points (i.e. reproduces the data points exactly) and can be used to estimate data points in-between the given ones. It is necessary because in science and engineering we often need to deal with discrete experimental data. Interpolation is also used to simplify complicated functions by sampling data points and interpolating them using a simpler function. Polynomials are commonly used for interpolation because they are easier to evaluate, differentiate, and integrate - known aspolynomial interpolation.

It can be proven that given n+1 data points it is always possible to find a polynomial of order/degree n to pass through/reproduce the n+1 points.

Direct Method

[edit |edit source]

Given n+1 data points the direct method assumes the following polynomial:

y=f(x)=a0+a1x+a2x2+...+anxn{\displaystyle y=f(x)=a_{0}+a_{1}x+a_{2}x^{2}+...+a_{n}x^{n}}

With n+1 values forx{\displaystyle x} and the n+1 corresponding values fory{\displaystyle y} we can solve fora0,a1,...,an{\displaystyle a_{0},a_{1},...,a_{n}} by solving the n+1 simultaneous linear equations, which is known as the direct method.

For example, given two data points(x0,y0){\displaystyle (x_{0},y_{0})} and(x1,y1){\displaystyle (x_{1},y_{1})} we can use a linear functiony=f(x)=a0+a1x{\displaystyle y=f(x)=a_{0}+a_{1}x} to pass through the two data points:

y0=a0+a1x0{\displaystyle y_{0}=a_{0}+a_{1}x_{0}}
y1=a0+a1x1{\displaystyle y_{1}=a_{0}+a_{1}x_{1}}

Once we solve fora0{\displaystyle a_{0}}anda1{\displaystyle a_{1}} (the coefficients off(x){\displaystyle f(x)}) we can use the function as the basis for interpolation - estimating the missing data points in-between.

Newton's Method

[edit |edit source]

In Newton's method the interpolating function is written inNewton polynomial(a.k.a Newton form). For example, given one data point(x0,y0){\displaystyle (x_{0},y_{0})} we can only derive a polynomial of order zero:y=f(x)=a0{\displaystyle y=f(x)=a_{0}}. Becausef(x0)=y0{\displaystyle f(x_{0})=y_{0}} the newton polynomial of order zero isy=f(x)=y0{\displaystyle y=f(x)=y_{0}}.

Given two data points we can write Newton's polynomial in the form ofy=f(x)=a0+a1(xx0){\displaystyle y=f(x)=a_{0}+a_{1}(x-x_{0})}. Plugging in the two data points gives us

a0=y0{\displaystyle a_{0}=y_{0}}
a1=y1y0x1x0{\displaystyle a_{1}={\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}}

Obviously this function passes through both data points (i.e. accurately reproduces the two data points). The first derivative of the function atx=x0{\displaystyle x=x_{0}} isf(x0)=a1=y1y0x1x0{\displaystyle f'(x_{0})=a_{1}={\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}}, which matches the result from the forward divided difference method.

Given three data points we can write Newton's polynomial in the form of

y=f(x)=a0+a1(xx0)+a2(xx1)(xx0){\displaystyle y=f(x)=a_{0}+a_{1}(x-x_{0})+a_{2}(x-x_{1})(x-x_{0})}

Plugging in the three data points gives us

Asy0=a0{\displaystyle y_{0}=a_{0}} we geta0=y0{\displaystyle a_{0}=y_{0}}
Asy1=a0+a1(x1x0){\displaystyle y_{1}=a_{0}+a_{1}(x_{1}-x_{0})} we geta1=y1y0x1x0{\displaystyle a_{1}={\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}}
Asy2=a0+a1(x2x0)+a2(x2x1)(x2x0){\displaystyle y_{2}=a_{0}+a_{1}(x_{2}-x_{0})+a_{2}(x_{2}-x_{1})(x_{2}-x_{0})}
we get
a2=y2a0a1(x2x0)(x2x1)(x2x0)=y2y0y1y0x1x0(x2x0)(x2x1)(x2x0)=y2y0y1y0x1x0((x2x1)+(x1x0))(x2x1)(x2x0)=y2y0y1y0x1x0(x2x1)(y1y0)(x2x1)(x2x0)=y2y1y1y0x1x0(x2x1)(x2x1)(x2x0)=y2y1x2x1y1y0x1x0x2x0{\displaystyle {\begin{aligned}a_{2}&={\frac {y_{2}-a_{0}-a_{1}(x_{2}-x_{0})}{(x_{2}-x_{1})(x_{2}-x_{0})}}\\&={\frac {y_{2}-y_{0}-{\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}(x_{2}-x_{0})}{(x_{2}-x_{1})(x_{2}-x_{0})}}\\&={\frac {y_{2}-y_{0}-{\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}((x_{2}-x_{1})+(x_{1}-x_{0}))}{(x_{2}-x_{1})(x_{2}-x_{0})}}\\&={\frac {y_{2}-y_{0}-{\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}(x_{2}-x_{1})-(y_{1}-y_{0})}{(x_{2}-x_{1})(x_{2}-x_{0})}}\\&={\frac {y_{2}-y_{1}-{\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}(x_{2}-x_{1})}{(x_{2}-x_{1})(x_{2}-x_{0})}}\\&={\frac {{\frac {y_{2}-y_{1}}{x_{2}-x_{1}}}-{\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}}{x_{2}-x_{0}}}\\\end{aligned}}}

This third degree polynomial function passes all three data points (the second derivative and the third derivative atx0{\displaystyle x_{0}} andx1{\displaystyle x_{1}}match that from the divided difference method).

From the two examples we can see the coefficients of a Newton polynomial follow a pattern known asdivided difference. For examplea1=y1y0x1x0{\displaystyle a_{1}={\frac {y_{1}-y_{0}}{x_{1}-x_{0}}}} is called divided difference of order 1 (denoted asf[x0,x1]{\displaystyle f[x_{0},x_{1}]}) because it depends onx0{\displaystyle x_{0}} andx1{\displaystyle x_{1}}. The divided difference notation can be used to write the general order (form) Newton polynomial:

f(x)=f[x0]+f[x0,x1](xx0)+f[x0,x1,x2](xx0)(xx1)+...{\displaystyle 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[x0,x1,x2,...,xn](xx0)(xx1)(xx2)...(xxn1){\displaystyle +f[x_{0},x_{1},x_{2},...,x_{n}](x-x_{0})(x-x_{1})(x-x_{2})...(x-x_{n-1})}

Where

a0=f[x0]=y0{\displaystyle a_{0}=f[x_{0}]=y_{0}} becausef[xi]=yi{\displaystyle f[x_{i}]=y_{i}} by definition
a1=f[x0,x1]=f[x1]f[x0]x1x0{\displaystyle a_{1}=f[x_{0},x_{1}]={\frac {f[x_{1}]-f[x_{0}]}{x_{1}-x_{0}}}}
a2=f[x0,x1,x2]=f[x1,x2]f[x0,x1]x2x0{\displaystyle a_{2}=f[x_{0},x_{1},x_{2}]={\frac {f[x_{1},x_{2}]-f[x_{0},x_{1}]}{x_{2}-x_{0}}}}
{\displaystyle \dots }
ak=f[x0,x1,x2,,xk1,xk]=f[x1,x2,,xk1,xk]f[x0,x1,x2,,xk1]xkx0{\displaystyle a_{k}=f[x_{0},x_{1},x_{2},\dots ,x_{k-1},x_{k}]={\frac {f[x_{1},x_{2},\dots ,x_{k-1},x_{k}]-f[x_{0},x_{1},x_{2},\dots ,x_{k-1}]}{x_{k}-x_{0}}}}

We can calculate the coefficients of Newton polynomial using the following table

x0y0=f[x0]f[x0,x1]x1y1=f[x1]f[x0,x1,x2]f[x1,x2]f[x0,x1,x2,x3]x2y2=f[x2]f[x1,x2,x3]f[x2,x3]x3y3=f[x3]{\displaystyle {\begin{matrix}x_{0}&y_{0}=f[x_{0}]&&&\\&&f[x_{0},x_{1}]&&\\x_{1}&y_{1}=f[x_{1}]&&f[x_{0},x_{1},x_{2}]&\\&&f[x_{1},x_{2}]&&f[x_{0},x_{1},x_{2},x_{3}]\\x_{2}&y_{2}=f[x_{2}]&&f[x_{1},x_{2},x_{3}]&\\&&f[x_{2},x_{3}]&&\\x_{3}&y_{3}=f[x_{3}]&&&\\\end{matrix}}}

because

f[xi]=yi{\displaystyle f[x_{i}]=y_{i}}
f[xi,xi+1]=f[xi+1]f[xi]xi+1xi{\displaystyle f[x_{i},x_{i+1}]={\frac {f[x_{i+1}]-f[x_{i}]}{x_{i+1}-x_{i}}}}

The following figures shows the dependency between the divided differences:

A table for solving the coefficients of a Newton's polynomial.

For example, given data points(1,6){\displaystyle (1,6)},(2,11){\displaystyle (2,11)},(3,18){\displaystyle (3,18)}, and(4,27){\displaystyle (4,27)} we can draw the following table:

ixiyif[xi,xi+1]f[xi,xi+1,xi+2]f[xi,xi+1,xi+2,xi+3]0x0=1y0=f[x0]=6f[x0,x1]=f[x1]f[x0]x1x0=11621=5f[x0,x1,x2]=f[x1,x2]f[x0,x1]x2x0=7531=1f[x0,x1,x2,x3]=f[x1,x2,x3]f[x0,x1,x2]x3x0=1141=01x1=2y1=f[x1]=11f[x1,x2]=f[x2]f[x1]x2x1=181132=7f[x1,x2,x3]=f[x2,x3]f[x1,x2]x3x1=9742=12x2=3y2=f[x2]=18f[x2,x3]=f[x3]f[x2]x3x2=271843=93x3=4y3=f[x3]=27{\displaystyle {\begin{array}{|c||c|c|c|c|c|}i&x_{i}&y_{i}&f[x_{i},x_{i+1}]&f[x_{i},x_{i+1},x_{i+2}]&f[x_{i},x_{i+1},x_{i+2},x_{i+3}]\\\hline 0&x_{0}=1&{\begin{aligned}y_{0}&=f[x_{0}]\\&=6\end{aligned}}&{\begin{aligned}f[x_{0},x_{1}]&={\frac {f[x_{1}]-f[x_{0}]}{x_{1}-x_{0}}}\\&={\frac {11-6}{2-1}}\\&=5\end{aligned}}&{\begin{aligned}f[x_{0},x_{1},x_{2}]&={\frac {f[x_{1},x_{2}]-f[x_{0},x_{1}]}{x_{2}-x_{0}}}\\&={\frac {7-5}{3-1}}\\&=1\end{aligned}}&{\begin{aligned}&f[x_{0},x_{1},x_{2},x_{3}]\\&={\frac {f[x_{1},x_{2},x_{3}]-f[x_{0},x_{1},x_{2}]}{x_{3}-x_{0}}}\\&={\frac {1-1}{4-1}}\\&=0\end{aligned}}\\\hline 1&x_{1}=2&{\begin{aligned}y_{1}&=f[x_{1}]\\&=11\end{aligned}}&{\begin{aligned}f[x_{1},x_{2}]&={\frac {f[x_{2}]-f[x_{1}]}{x_{2}-x_{1}}}\\&={\frac {18-11}{3-2}}\\&=7\end{aligned}}&{\begin{aligned}f[x_{1},x_{2},x_{3}]&={\frac {f[x_{2},x_{3}]-f[x_{1},x_{2}]}{x_{3}-x_{1}}}\\&={\frac {9-7}{4-2}}\\&=1\end{aligned}}&\\\hline 2&x_{2}=3&{\begin{aligned}y_{2}&=f[x_{2}]\\&=18\end{aligned}}&{\begin{aligned}f[x_{2},x_{3}]&={\frac {f[x_{3}]-f[x_{2}]}{x_{3}-x_{2}}}\\&={\frac {27-18}{4-3}}\\&=9\end{aligned}}&&\\\hline 3&x_{3}=4&{\begin{aligned}y_{3}&=f[x_{3}]\\&=27\end{aligned}}&&&\\\end{array}}}

The four data points lie on a polynomial of order 2, which is why the coefficienta3{\displaystyle a_{3}}(f[x0,x1,x2,x3]{\displaystyle f[x_{0},x_{1},x_{2},x_{3}]}) is zero. Given[a0,a1,a2]=[6,5,1]{\displaystyle [a_{0},a_{1},a_{2}]=[6,5,1]} the result polynomial is:

y=a0+a1(xx0)+a2(xx1)(xx0)=6+5×(x1)+1×(x2)(x1)=x2+2x+3{\displaystyle {\begin{aligned}y&=a_{0}+a_{1}(x-x_{0})+a_{2}(x-x_{1})(x-x_{0})\\&=6+5\times (x-1)+1\times (x-2)(x-1)\\&=x^{2}+2x+3\end{aligned}}}

Once the coefficients of a Newton's polynomial are solved, we can evaluate the polynomial function for anyx{\displaystyle x}. A Newton polynomial is often rewritten in a nested form:

f(x)=a0+(xx0)(a1+(xx1)(a2+(xx2)(a3+...+an(xxn1))...){\displaystyle f(x)=a_{0}+(x-x_{0})(a_{1}+(x-x_{1})(a_{2}+(x-x_{2})(a_{3}+...+a_{n}(x-x_{n-1}))...)},

because this nested form of interpolating polynomial is easier to evaluate because x only appears in the function n times.

For example, the nested form of a third order interpolating polynomial is:

f(x)=a0+(xx0)(a1+(xx1)(a2+(xx2)a3)){\displaystyle f(x)=a_{0}+(x-x_{0})(a_{1}+(x-x_{1})(a_{2}+(x-x_{2})a_{3}))}

The algorithm of Newton's method and its implementation can be found in thisJupyter notebook.

Lagrange Form

[edit |edit source]

Lagrange polynomial is another form used for polynomial interpolation. It is called a form because with a given set of distinct points the interpolating polynomial is unique. We can arrive at the same polynomial through different methods.

The Lagrange form specifies the interpolation polynomial as:

fn(x):=i=0nLi(x)f(xi){\displaystyle f_{n}(x):=\sum _{i=0}^{n}L_{i}(x)f(x_{i})}
Li(x):=0mnmixxmxixm=(xx0)(xix0)(xxi1)(xixi1)(xxi+1)(xixi+1)(xxn)(xixn),{\displaystyle L_{i}(x):=\prod _{\begin{smallmatrix}0\leq m\leq n\\m\neq i\end{smallmatrix}}{\frac {x-x_{m}}{x_{i}-x_{m}}}={\frac {(x-x_{0})}{(x_{i}-x_{0})}}\cdots {\frac {(x-x_{i-1})}{(x_{i}-x_{i-1})}}{\frac {(x-x_{i+1})}{(x_{i}-x_{i+1})}}\cdots {\frac {(x-x_{n})}{(x_{i}-x_{n})}},}

wheren{\displaystyle n} is the order of the polynomial.

For example, given two data points we getn=1{\displaystyle n=1} and

f(x)=L0f(x0)+L1f(x1)=xx1x0x1f(x0)+xx0x1x0f(x1){\displaystyle {\begin{aligned}f(x)&=L_{0}f(x_{0})+L_{1}f(x_{1})\\&={\frac {x-x_{1}}{x_{0}-x_{1}}}f(x_{0})+{\frac {x-x_{0}}{x_{1}-x_{0}}}f(x_{1})\\\end{aligned}}}

Obviously the function curve passes both data points. The first derivative also matches that of the divided difference method:

f(x)=f(x0)x0x1+f(x1)x1x0=f(x1)f(x0)x1x0{\displaystyle {\begin{aligned}f'(x)&={\frac {f(x_{0})}{x_{0}-x_{1}}}+{\frac {f(x_{1})}{x_{1}-x_{0}}}\\&={\frac {f(x_{1})-f(x_{0})}{x_{1}-x_{0}}}\\\end{aligned}}}

Spline Interpolation

[edit |edit source]

Spline interpolation uses a number of polynomial functions to interpolate a set of data points with each polynomial for two adjacent data points. The Spline method is necessary because often times when the order of the polynomial become large polynomial interpolation shows oscillatory behavior (instability known asRunge's phenomenon). The following iPython notebook shows an example that suffers this issue:[1]

Spline method is not another method for finding polynomial interpolation of a discrete function, but instead it results in a piecewise polynomial (splines) in order to avoid the oscillatory behavior. The most common spline interpolations are linear, quadratic, and cubic splines.Linear interpolation uses lines to connect each pair of consecutive data points resulting in a piecewise interpolation.

Interpolation example linear

Aquadratic spline uses a quadratic polynomial to connect consecutive data points.

Quadratic spline six segments

A function f(x) is a quadratic spline if the following conditions are true:

  1. The domain off(x){\displaystyle f(x)} is an interval [a, b].
  2. f(x){\displaystyle f(x)} andf(x){\displaystyle f'(x)} are continuous on [a, b].
  3. The data pointsxi{\displaystyle x_{i}} such thata=x0<x1<<xn=b{\displaystyle a=x_{0}<x_{1}<\dots <x_{n}=b} andf(x){\displaystyle f(x)} is a polynomial of order at most 2 on each subinterval[xi,xi+1]{\displaystyle [x_{i},x_{i+1}]}.
Retrieved from "https://en.wikibooks.org/w/index.php?title=Introduction_to_Numerical_Methods/Interpolation&oldid=3796034"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp