3.1 Interpolation and Lagrange Polynomial
Transcript of 3.1 Interpolation and Lagrange Polynomial
![Page 1: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/1.jpg)
3.1 Interpolation and Lagrange Polynomial
1
![Page 2: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/2.jpg)
Example. Daily Treasury Yield Curve Rates
Suppose we want yield rate for a four-years maturity bond, what shall we do?
Ref: http://www.treasury.gov/resource-center/data-chart-center/interest-rates/Pages/TextView.aspx?data=yield2
Date 1 Mo 3 Mo 6 Mo 1 Yr 2 Yr 3 Yr 5 Yr 7 Yr 10 Yr 20 Yr 30 Yr
09/01/15
0.01 0.03 0.26 0.39 0.70 1.03 1.49 1.89 2.17 2.62 2.93
Solution: Draw a smooth curve passing through these data points (interpolation).
![Page 3: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/3.jpg)
โข Interpolation problem: Find a smooth function ๐ ๐ฅ which interpolates (passes) the data (๐ฅ$, ๐ฆ$) $()
* .
โข Remark: In this class, we always assume that the data ๐ฆ$ $()
* represent measured or computed values of a underlying function ๐ ๐ฅ , i.e., ๐ฆ$ =๐(๐ฅ$). Thus ๐ ๐ฅ can be considered as an approximation to ๐.
3
![Page 4: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/4.jpg)
Polynomial Interpolation
Polynomials ๐- ๐ฅ = ๐-๐ฅ- +โฏ+ ๐1๐ฅ1 + ๐2๐ฅ + ๐)are commonly used for interpolation.
ร Advantages for using polynomial: efficient, simple mathematical operation such as differentiation and integration.
Theorem 3.1 Weierstrass Approximation theorem Suppose ๐ โ ๐ถ[๐, ๐]. Then โ๐ > 0, โ a polynomial ๐ ๐ฅ :๐ ๐ฅ โ ๐ ๐ฅ < ๐, โ๐ฅ โ ๐, ๐ .
Remark: 1. The bound is uniform, i.e. valid for all ๐ฅ in ๐, ๐ . This means polynomials are good at approximating general functions.2. But the way to find ๐ ๐ฅ is unknown.
4
![Page 5: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/5.jpg)
โข Question: Can Taylor polynomial be used here?โข Taylor expansion is accurate in the neighborhood of one point.
But we need the (interpolating) polynomial to pass many points.
โข Example. Taylor polynomial approximation of ๐B for ๐ฅ โ [0,3]
5
![Page 6: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/6.jpg)
โข Another bad Example. Taylor polynomial approximation of 2B
for ๐ฅ โ [0.5,5]. Taylor polynomials of different degrees are expanded at ๐ฅ) = 1
6
![Page 7: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/7.jpg)
๐๐๐ -degree Lagrange Interpolating PolynomialGoal: construct a polynomial of degree 2 passing 3 data points ๐ฅ), ๐ฆ) , ๐ฅ2, ๐ฆ2 , ๐ฅ1, ๐ฆ1 .Step 1: construct a set of basis polynomials ๐ฟ1,J ๐ฅ , ๐ =0,1,2 satisfying
๐ฟ1,J ๐ฅM = N1, when ๐ = ๐0, when ๐ โ ๐
These polynomials are:
๐ฟ1,) ๐ฅ =(๐ฅ โ ๐ฅ2)(๐ฅ โ ๐ฅ1)(๐ฅ) โ ๐ฅ2)(๐ฅ) โ ๐ฅ1)
,
๐ฟ1,2 ๐ฅ =(๐ฅ โ ๐ฅ))(๐ฅ โ ๐ฅ1)(๐ฅ2 โ ๐ฅ))(๐ฅ2 โ ๐ฅ1)
,
๐ฟ1,1 ๐ฅ =(๐ฅ โ ๐ฅ))(๐ฅ โ ๐ฅ2)(๐ฅ1 โ ๐ฅ))(๐ฅ1 โ ๐ฅ2) 7
![Page 8: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/8.jpg)
Step 2: form the 2nd-degree Lagrange interpolating polynomial ๐ ๐ฅ :
๐ ๐ฅ = ๐ฆ)๐ฟ1,) ๐ฅ + ๐ฆ2๐ฟ1,2 ๐ฅ + ๐ฆ1๐ฟ1,1 ๐ฅ
Verification:a) ๐ ๐ฅ is a 2nd โdegree polynomialb) ๐ ๐ฅ satisfy the interpolation property:
๐ ๐ฅ) = ๐ฆ), ๐ ๐ฅ2 = ๐ฆ2, ๐ ๐ฅ1 = ๐ฆ1.
8
![Page 9: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/9.jpg)
Example 1. Use nodes ๐ฅ) = 0, ๐ฅ2 = 1, ๐ฅ1 = 2 to find 2nd Lagrange interpolating polynomial ๐ ๐ฅfor ๐ ๐ฅ = 2
BU2. And use ๐ ๐ฅ to approximate
๐ V1.
9
![Page 10: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/10.jpg)
๐-degree Interpolating Polynomial through ๐ + ๐ Points
Constructing a Lagrange interpolating polynomial ๐ ๐ฅpassing through the points (๐ฅ), ๐ ๐ฅ) ), ๐ฅ2, ๐ ๐ฅ2 ,๐ฅ1, ๐ ๐ฅ1 , โฆ , (๐ฅ-, ๐ ๐ฅ- ).
1. Define Lagrange basis functions ๐ฟ-,J ๐ฅ =โ$(),$ZJ- B[B\
B][B\= B[B^
B][B^โฆ B[B]_`B][B]_`
aB[B]b`B][B]b`
โฆ B[BcB][Bc
for ๐ = 0,1โฆ๐.
Remark: ๐ฟ-,J ๐ฅJ = 1; ๐ฟ-,J ๐ฅ$ = 0, โ๐ โ ๐
2. ๐ ๐ฅ = ๐ ๐ฅ) ๐ฟ-,) ๐ฅ + โฏ+ ๐ ๐ฅ- ๐ฟ-,- ๐ฅ .
10
![Page 11: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/11.jpg)
โข ๐ฟj,V(๐ฅ) for points ๐ฅ$ = ๐, ๐ = 0,โฆ , 6.
11
![Page 12: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/12.jpg)
Theorem 3.2 If ๐ฅ), โฆ , ๐ฅ- are ๐ + 1distinct numbers (called nodes) and ๐ is a function whose values are given at these numbers, then a unique polynomial ๐(๐ฅ) of degree at most ๐ exists with ๐ ๐ฅJ =๐ ๐ฅJ , for each ๐ = 0, 1, โฆ ๐.๐ ๐ฅ = ๐ ๐ฅ) ๐ฟ-,) ๐ฅ + โฏ+ ๐ ๐ฅ- ๐ฟ-,- ๐ฅ .
Where ๐ฟ-,J ๐ฅ = โ$(),$ZJ- B[B\
B][B\.
12
![Page 13: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/13.jpg)
Error Bound for the Lagrange Interpolating Polynomial
Theorem 3.3. Suppose ๐ฅ), โฆ , ๐ฅ- are distinct numbers in the interval [๐, ๐] and ๐ โ ๐ถ-U2 ๐, ๐ . Then, for each ๐ฅ in [๐, ๐], a number ๐(๐ฅ) (generally unknown) in ๐, ๐ exists with
๐ ๐ฅ = ๐ ๐ฅ + o cb` p B-U2 !
๐ฅ โ ๐ฅ) ๐ฅ โ ๐ฅ2 โฆ ๐ฅ โ ๐ฅ-Where ๐ ๐ฅ is the nth-degree Lagrange interpolating polynomial.
13
Remark: It is usually very difficult to estimate the absolute error |๐ ๐ฅ โ ๐ ๐ฅ | using Theorem 3.3: (1) the term |๐ -U2 ๐ ๐ฅ | is hard to estimate for a
general function ๐. (2) the term ๐ฅ โ ๐ฅ) ๐ฅ โ ๐ฅ2 โฆ ๐ฅ โ ๐ฅ- is oscillatory and
its extreme value is hard to calculate for large value ๐.
![Page 14: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/14.jpg)
Graph of ๐ฅ โ 0 ๐ฅ โ 1 ๐ฅ โ 2 ๐ฅ โ 3 ๐ฅ โ 4
14
![Page 15: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/15.jpg)
Example 2. The 2nd Lagrange polynomial for ๐ ๐ฅ = 2
BU2on [0, 2] using nodes ๐ฅ) = 0, ๐ฅ2 =
1, ๐ฅ1 = 2 is ๐ ๐ฅ = 2j๐ฅ1 โ 1
V๐ฅ + 1.
Determine the error form for ๐ ๐ฅ , and maximum error when the polynomial is used to approximate ๐ ๐ฅ for ๐ฅ โ 0,2 .
[MATLAB demo next slide]
15
![Page 16: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/16.jpg)
16
F = @(x) 1./(x+1);P = @(x) 1/6*x.^2-2/3*x+1;xNodes = [0,1,2];yNodes = F(xNodes);
X = linspace(0,2,10000); % sample 10000 pointsFX = F(X);PX = P(X);fprintf('\n Max-err: %.4e\n', max(abs(FX-PX))) % the maximum error
figure(1) % plot function and interpolantplot(X,FX, 'b', X, PX, 'r', xNodes, yNodes, 'ko','LineWidth',4)legend('F(x)', 'P(x)','Nodes')set(gca, 'FontSize',24)
figure(2) % plot the absolute errorplot(X, abs(FX-PX),'LineWidth',4)title('Absolute error')set(gca, 'FontSize',24)
Max-err: 4.6344e-02
1
![Page 17: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/17.jpg)
Example 3 (MATLAB). Plot the 4th Lagrange interpolating polynomial for
๐ ๐ฅ = 22U1t Bu
on the interval [โ1, 1] using 5 uniform nodes ๐ฅ) = โ1, ๐ฅ2 = โ0.5, ๐ฅ1 = 0, ๐ฅV = 0.5, ๐ฅv = 1.On the same figure, plot the original function ๐ ๐ฅ and the interpolation nodes.
17
![Page 18: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/18.jpg)
18
lagrange_basis.m
STEP 1: Lagrange Basis function (function .m file)
function phi_k = lagrange_basis(x, xnodes, k)% function phi_k = lagrange_basis(x, xnodes, k)% ### The Lagrange Basis/ or Lagrange Characteristic poly ###%% Input:% x: a vector of x-values/ or a symbolic variable% xnodes: a vector of size (n+1) storing the values of x_k(k=0,...,n)% k: a integer in the range 0 - n.% Output:% phi_k: k-th (degree n) Lagrange basis eval @ x
n = length(xnodes)-1; % poly degreexk = xnodes(k+1);
phi_k = 1;for i = 0:n if i == k continue; end phi_k = phi_k.*(x-xnodes(i+1))/(xk-xnodes(i+1));end
return
Not enough input arguments.
Error in lagrange_basis (line 12)n = length(xnodes)-1; % poly degree
Published with MATLABยฎ R2019a
1
![Page 19: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/19.jpg)
19
lagrange_interp.m
STEP 2: Lagrange Interpolation (script .m file)
% function and interpolation nodesf = @(x) 1./(1+25*x.*x);n = 4; % degree 4 interpolationxNodes = linspace(-1,1,n+1);yNodes = f(xNodes);
% evaluate function at 1001 uniform pointsm = 1001;xGrid = linspace(-1,1,m);pGrid = zeros(size(xGrid));
for k = 0:n yk = yNodes(k+1); phi_k = lagrange_basis(xGrid, xNodes, k); % k-th basis eval @ xGrid pGrid = pGrid + yk*phi_k;end
plot(xGrid, f(xGrid),'b', xGrid, pGrid, 'r', xNodes, yNodes, 'ko',... 'LineWidth', 4)legend('F(x)', 'P(x)','Nodes')set(gca, 'FontSize',24)
Published with MATLABยฎ R2019a
1
![Page 20: 3.1 Interpolation and Lagrange Polynomial](https://reader030.fdocuments.us/reader030/viewer/2022012518/6192ae18f2abdb311f3356b4/html5/thumbnails/20.jpg)
20
% function and interpolation nodesf = @(x) 1./(1+25*x.*x);n = 4; % degree 4 interpolationxNodes = linspace(-1,1,n+1);yNodes = f(xNodes);
% evaluate function at 1001 uniform pointsm = 1001;xGrid = linspace(-1,1,m);pGrid = zeros(size(xGrid));
for k = 0:n yk = yNodes(k+1); phi_k = lagrange_basis(xGrid, xNodes, k); % k-th basis eval @ xGrid pGrid = pGrid + yk*phi_k;end
plot(xGrid, f(xGrid),'b', xGrid, pGrid, 'r', xNodes, yNodes, 'ko',... 'LineWidth', 4)legend('F(x)', 'P(x)','Nodes')set(gca, 'FontSize',24)
Published with MATLABยฎ R2019a
1
The figure (run โซ lagrange_interp on command window)