3.1 interpolation and lagrange polynomial

20
3.1 Interpolation and Lagrange Polynomial 1

Upload: others

Post on 16-Nov-2021

28 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3.1 Interpolation and Lagrange Polynomial

3.1 Interpolation and Lagrange Polynomial

1

Page 2: 3.1 Interpolation and Lagrange Polynomial

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

โ€ข 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

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

โ€ข 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

โ€ข 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

๐Ÿ๐’๐’…-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

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

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

๐’-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

โ€ข ๐ฟj,V(๐‘ฅ) for points ๐‘ฅ$ = ๐‘–, ๐‘– = 0,โ€ฆ , 6.

11

Page 12: 3.1 Interpolation and Lagrange Polynomial

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

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

Graph of ๐‘ฅ โˆ’ 0 ๐‘ฅ โˆ’ 1 ๐‘ฅ โˆ’ 2 ๐‘ฅ โˆ’ 3 ๐‘ฅ โˆ’ 4

14

Page 15: 3.1 Interpolation and Lagrange Polynomial

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

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

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

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

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

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)