BSM510 Numerical Analysis Polynomial Interpolation Prof. Manar Mohaisen Department of EEC Engineering
Review of Precedent Lecture Polynomial Regression Multiple Linear Regression Nonlinear Regression
Lecture Content Introduction to Interpolation Newton Interpolation Polynomial Lagrange Interpolation Polynomial Extrapolation and Oscillations 3
Introduction to Interpolation Interpolation Estimate intermediate values between precise data points Polynomial interpolation Using n data points, find an (n-1)th-order polynomial that passes by all the points Matlab format f() x = a + a x + a x + L + a xn 1 3 1 n f x = px + p x + + p x + p () n 1 n L 1 n 1 n 4
Introduction to Interpolation Determining Polynomial Coefficients Example nd order polynomial f() x = px + p x + p 1 3 x 300 400 500 f(x) 0.616 0.55 0.457 p(300) + p (300) + p = 0.616 1 3 p(400) + p (400) + p = 0.55 1 3 p(500) + p (500) + p = 0.457 1 3 90,000 300 1 p 0.616 160,000 400 1 p = 0.55 50,000 500 1 p 0.457 1 3 y 0.7 06 0.6 0.5 p 0.00000115 1 p 0.001715 = p 3 1.070000 0.4 300 350 400 450 500 x 5
Introduction to Interpolation Drawback of the precedent algorithm Vandermonde matrix 90,000000 300 1 A = 160,000 400 1 cond( A) = 3.893 106 50,000 500 1 Matrices of this type are very ill-conditioned! Look for alternative methods! % file: nd order polynomial interpolation format long x =[300 400 500]; y = [0.616 0.55 0.457]; p = polyfir(x, y, ); % find intermediate value >> d = polyval(p, 350) d = 0.56765 6
Newton Interpolation Polynomial Linear Interpolation f ( x) f( x ) f( x ) f( x ) f( x ) f( x ) = f () x = f( x ) + ( x x ) 1 1 1 1 x x x x 1 1 x x 1 1 1 1 Example (log() = 0.693147) Find log() using log(1) and log(6) Find log() using log(1) and log(4).5 1.71759 0 f () = 0 + ( 1) = 0.3583519 1 6 1 1.38694 0 f () = 0 + ( 1) = 0.460981 1 4 1 1.5 y 1 0.5 1 3 4 5 6 7 8 0 x 7
Newton Interpolation Polynomial Quadratic Interpolation f () x = b + b ( x x ) + b ( x x )( x x ) 1 1 3 1 Substitute with x = x 1 f ( x ) = b 1 1 Substitute x = x b = f( x ) f( x ) 1 x x 1 Finally, b 3 = f( x ) f( x ) f( x ) f( x ) 3 1 x x x x 3 1 x x 3 1 8
Newton Interpolation Polynomial Quadratic Interpolation Example x 1 4 5 f(x) 0 1.38694 1.79159 0 = b 1 b f( x ) f( x ) = 1 x x = 1 0.460981 b 3 f( x ) f( x ) f( x ) f( x ) 3 1 x x x x = 3 1 x x = 3 1 0.0518731 Then, f () 0.460981( 1) 0.0518731( 0518731( 1)( 4) x = x x x f () 0.5658444 = 9
Newton Interpolation Polynomial General Form of Newton s Interpolating Polynomials f ( x) = b + b ( x x ) + L+ b ( x x )( x x ) L( x x ) 1 1 n 1 n 1 With b = f( x ) 1 1 b = f[ x, x ] 1 f( x ) f( x ) fx [, x] = i j i j x x i j b = f[ x, x, x ] 3 1 b 3 = f[ x, x ] f[ x, x ] 3 1 x x 3 1 b = f[ x, x, L, x, x ] n n n 1 1 10
Newton Interpolation Polynomial Graphical depiction Finite divided difference Divided difference table x i f(x i ) First Second Third x 1 f(x 1 ) f[x,x 1 ] f[x 3,x,x 1 ] f[x 4, x 3,x,x 1 ] 1 1 1 3 1 4 3 1 x f(x ) f[x 3,x ] f[x 4, x 3,x ] x 3 f(x 3 ) f[x 4,x 3 ] x 4 f(x 4 ) 11
Newton Interpolation Polynomial Example Estimate log() with a third-order Newton s interpolating polynomial f ( x) = b + b ( x x ) + b ( x x )( x x ) + b ( x x )( x x )( x x ) 3 1 1 3 1 4 1 3 x i f(x i ) First Second Third 1 0 0.460981 0.051873110 05187311 0.0078655900786559 4 1.38694 0.0736 0.0041100 6 1.791759 0.18316 5 1.609438 f 3 () x = 0.460981 ( x 1) 0.05187311( 05187311( x 1)( x 4) + 0.00786559 ( x 1)( x 4)( x 6) f () = 0.687686 3 1
Lagrange Interpolation Polynomial Linear Lagrange Interpolation Polynomial x x x x f ( x ) = L f ( x ) + L f ( x ) = f ( x ) + f ( x ) 1 11 1 x x 1 x x 1 1 nd-order Lagrange Interpolation Polynomial ( x x )( x x ) ( x x )( x x ) ( x x )( x x ) f () x = f( x ) + f( x ) + f( x ) 3 1 3 1 ( x x )( x x ) 1 ( x x )( x x ) ( x x )( x x ) 3 1 1 3 1 3 1 3 (n-1)th-order Lagrange Interpolation Polynomial n n i i i x = 1 = 1 i x x f () x L()( x f x ), L() x n 1 = = x i j i j j 13
Lagrange Interpolation Polynomial Example Estimate f(15) Linear Interpolation x i 0 0 40 f(x i ) 3.85 0.8 0.1 x x x x 15 0 15 0 fx ( ) = x x fx ( ) + x x fx ( ) = 3.85+ 0.800 = 1.565 0 0 0 0 1 1 1 1 nd-order interpolation ( x x )( x x ) ( x x )( x x ) ( x x )( x x ) f () x = 3 f( x ) + 1 3 f( x ) + 1 f( x ) ( x x )( x x ) 1 ( x x )( x x ) ( x x )( x x ) 3 1 1 3 1 3 1 3 (15 0)(15 40) (15 0)(15 40) (15 0)(15 0) = 3.85 + 0.8 + 0.1 = 1.331 6875 (0 0)(0 40) (0 0)(0 40) (0 0)(40 0) 14
Inverse Interpolation Given f(x), we need to find x f(x) 0.149 0.1667 0. 0.5 0.3333 0.5 1 x 7 6 5 4 3 1 Solution 1: switch the values of x and f(x) The values of the new x is not guaranteed to be evenly spaced This leads to oscillations in the obtained function Solution : maintain x and f(x) Obtain the polynomial as a function of x Solve the root of the equation Example: f ( x ) = 0.041667 0.375 x + 1.08333 Find x such that f(x) = 0.3 0.3 = 0.041667 0.375x + 1.08333 x = 5.704158, 3.9584 15
Extrapolation and Oscillation Extrapolation Estimating a value of f(x) that lies outside the range of known points x i 16
Dangers of Extrapolation Example 190 1930 1940 1950 1960 1970 1980 1990 000 106.46 13.08 13.11 15.77 180.67 05.05 7.33 49.4646 81.4 Interpolate the first 8 points using 7-th order polynomial Find f(x) at 000 using the interpolation function Result: f(000) = 175.0800 17
Oscillations Interpolation The more is the better? (higher order polynomial is better than lower order polynomials?) Not usually true: higher order polynomials are ill-conditioned (sensitive) Example: Runge s function f() x = 1 1 + 5x x 18
Lecture Summary Introduction to Interpolation Newton Interpolation Polynomial Lagrange Interpolation Polynomial Extrapolation and Oscillations 19