Polynomial Interpolation and Approximation

Polynomial Interpolation and Approximation

Polynomial Interpolation and Approximation Errors using inadequate data are much less than those using no data at all. Charles Babbage 1 Fall 2010 Topics to Be Discussed zThis unit only requires the knowledge of simple polynomial algebra and algebraic manipulations. zThe following topics will be presented: ¾A naïve interpolation method ¾The Lagrange form ¾The Newton form ¾Divided Difference ¾Least square polynomial approximation 2 Polynomial Interpolation: 1/5 zIn many applications, we know a function but don’t know its exact form. For example: π /2 1 K()kdx= ∫0 22 1sin− ()kxsin () zThe above shows a function of k. But, what is this function K(k)? How do we plot K(k) ? Do we have to plug a value of k into the formula and integrate with respect to x to find K(k)? 3 Polynomial Interpolation: 2/5 zIf K(k) is simple, integration may be a viable approach; however, most integrations are difficult. This is a problem. zOne way to overcome this problem is to evaluate K(k) at some values of k and fit them with a simpler function (e.g., polynomial). zOne may use k0, k1, …, kn tltto evaluate K(k0), K(k1), …, K(kn), and fit (k0, K(k0)), (k1, K(k1)), …, (kn, K(kn)) with a polynomial y=P(x). zThen, when K(t) is needed, one uses P(t) instead! 4 Polynomial Interpolation: 3/5 zSince ppyolynomial y=P(x) pppasses all data points (ki,K(ki)) for i = 0, 2, …, n, P(x) is said to interpolate function K(k) at k0, k1, …, kn. zSince a degree n polynomial, P(x) = a0 + a1x + 2 n a2x + … + anx , has n+1 coefficients, n+1 distinct data points (ki,K(ki)) are needed to have a unique solution to a0, a1, a2, …, an. zPolynomials may have other forms, each of which requires a different computation. zWe will discuss the Lagrange and Newton forms. zInterpolating polynomials are unique. They j ust h ave diff eren t forms. 5 Polynomial Interpolation: 4/5 z Polyypnomial Interpolation: Given a set of data points (x0,y0), (x1,y1), …, (xn,yn), where xi’s are all distinct, find a polynomial y = P(x) that interpolates the data points (i.e., yi = P(xi) for i = 0, 1, …, n). The degree of the interpolating polynomial P(x) is n. Then, we may use P(x) as if it is the unknown function that generates data points (x0,y0), (x1,y1), …, (xn,yn). All transcendental functions (e.g., sin(), exp(), log())i) are computed this way. 6 Polynomial Interpolation: 5/5 zA number of fundamental issues have to be addressed properly: How easy can we determine the interpolating polynomial from the input data points? HtHow easy can we compute P(x) for a new x after the polynomial is determined? How easy can we add new data points after P(x) is determined? How efficient can we solve these three issues? 7 A Naïve Method: 1/3 zLet us tryygg a naïve method before getting into good ones. zSuppose the inter polatin g pol ynomial for n+1 2 n data points is P(x) = a0 + a1x + a2x + … + anx . In other words, P(x) is in the power form. zLet the data points be (x0,y0), (x1,y1), …, (xn,yn). zFor each xi,,g we have the following: ⎡a0 ⎤ ⎢a ⎥ ⎢⎥1 22…nn⎡⎤⎢ ⎥ yPxaaxaxii==++++=()01 ii 2 ax niiii⎣⎦ 1,, xx , , x ⋅ a 2 ⎢ ⎥ ⎢ ⎥ ⎢⎥ ⎣an ⎦ 8 A Naïve Method: 2/3 2 n zCollecting all [1,xi,xi ,…,xi ]’sintoas into a (n+1)×(n+1) matrix yields: 2 n ⎡⎤ya00⎡⎤1 xx00 x 0 ⎡⎤ ⎢ ⎥⎢⎥⎢ 2 n ⎥ ya1 xx x ⎢ 11⎥⎢⎥⎢⎥11 1 2 n ⎢⎥y22=⋅⎢1 xx x⎥ ⎢⎥a ⎢⎥⎢⎥22 2 ⎢⎥ ⎢ ⎥⎢⎥⎢⎥ ⎢ ⎥⎢⎥⎢⎥2 n ⎣⎦ynn⎣⎦1 xxnn x n ⎣⎦a zSince the column matrix [yj](n+1)×1 and the matrix [xi,j](n+1)×(n+1) are known (i.e., input data), Gaussian elimination may be used to solve for the a0, a1, a2,,…, …, an. 9 A Naïve Method: 3/3 zIssue #1: Determininggp poly nomial P(x) is not difficult with Gaussian elimination; however, it is an O(n3) method (i.e., slow)! zIssue #2: EltiEvaluating P(x) with a g iven x is efficient if one uses the nested form which requires n multiplications ( i.e., O(n)): aaa012++++( ( ( annn−− 2 + ( a 1 + axxxxx ))) )) zIssue #3: Adding a new data point requires solving a new system of linear equations. zMoreover, pivoting may be needed. 10 Lagrange Polynomials: 1/14 zLagggrange used a sp ecial form of P(x). zEach term of P(x) is a degree n polynomial, and the i-th term does not include x-xi. Px10110()=−+− a ( x x ) a ( x x ) P2012102201()()()()()()()x=− axxxx −+− axx xx −+− axxxx − Pxnn()=− a01 ( x x )( x − x 2 ) ( x −+ x ) ax10()()()−− x x x 2 x −+ xn ax()()()()−−− x x x x x x −+ x 20 1 3 n Pk(x) means degree k axnn()()()−− x01 x x x − x− 1 n P ()xa⎡⎤n ( xx ) General form nijjij= ∑ ⎣⎦∏ =≠0, − i=0 11 Lagrange Polynomials: 2/14 zWhyygg is the Lagrange form useful? zIt is easy to compute coefficients a0, a1, …, an. zThe i-th term of Pn(x) does not have x-xi: axiiin()()()()()−− x01 x x x − x−+ 1 x − x 1 x − x zTherefore, plugging one of x=x0, x=x1, …, x=xi-1, x=xi+1, …, x=xn into this term yields a zero. zHowever, plugging x=xi into this term yields: axii()()()()()−− x01 x i x x i − x i−+ 1 x i − x i 1 x i − x n zHence, xi makthkes the i-th term non-zero andlld all other terms zero. 12 Lagrange Polynomials: 3/14 zRecall that the Lagggrange form is n P ()xa⎡ n ( xx )⎤ nijjij=∏∑ ⎣ =≠0, −⎦ i=0 zIf we plug xi into Pn(xi) , all but the i-th term become zero, and the i-th term is axii()()()()()−− x01 x i x x i − x i−+ 1 x i − x i 1 x i − x n zTherefore, we have yPxaxxxxi==−− niii() (01 )( i ) ( xx ii −−+ 1 )( xx ii − 1 ) ( xx in − ) and ai is: yi ai = ()()()()()xxxxi−−01 i xx ii −−+ 1 xx ii − 1 xx i −n 13 Lagrange Polynomials: 4/14 zPlugging the comp uted ai’s back to Pn(x) yields the Lagrange interpolating polynomial. n ()()()()()xx−−01 xx xx −ii−+ 1 xx − 1 xx − n Pxni()= ∑ y i=0 ()()()()()xxxxi−−01 i xx ii −−+ 1 xx ii − 1 xx in − zGiven (xi,yi), i=0,1,…,n, the following computes all coefficients ai’s in array a(0:n): DO i = 0, n ! Compute ai a(i) = 1.0 DO j = 0, n ! For each xj, j != i IF (i /= j) a(i) = a(i)*(x(i) – x(j)) END DO a(i) = y(i)/a(i) END DO 14 Lagrange Polynomials: 5/14 zHow many multiplications are there? For each i, n multiplications are needed in the inner loop because it iterates n+1 times and no mu ltip licati on i s need ed if i = j. Since the outer DO loops for n+1 times, the total number of multiplications is n(n+1). This is high; but, it is easy to do! DO i = 0, n ! Compute ai a(i) = 1.0 DO j = 0, n ! For each xj, j != i IF (i /= j) a(i) = a(i)*(x(i) – x(j)) END DO a(i) = y(i)/a(i) END DO 15 Lagrange Polynomials: 6/14 zConsider three data points (-1,1), (0,2) and (1,5). Thus, x0=-1, y0=1, x1=0, y1=2 and x2=1, y2=5. zHere are the ai’s and the interpolating polynomial of degree 2: y0 11 a0 == = (xxxx0102−− )( ) (( −−×−− 1) 0) (( 1) 1) 2 y1 2 a1 == =−2 (xxxx1012−− )( ) (0 −−×− ( 1)) (0 1) y2 55 a2 === (xxxx2021−− )( ) (1 −−×− ( 1)) (1 0) 2 15 P2 ()xxxxx=−−+−++ (1)2(1)(1)(1) xx 2216 Lagrange Polynomials: 7/14 zHow to find Pn(x) for an arbitrary x? zThe polynomial Pn(x) is: n Pxni()= ∑ ax (−− x01 )( x x ) ( x − x iin−+ 1 )( x − x 1 ) ( x − x ) i=0 zThe number of multiplications is still n(n+1)! ! x is the input With some programming Px = 0.0 trick, one may reduce the DO i = 0, n number of multiplications s = a(i) to O(n)! How? DO j = 0, n (Hint: use division) IF (i /= j) s = s * (x – x(j)) END DO However, this approach Px = Px + s is risky. Why??? END DO 17 Lagrange Polynomials: 8/14 zWe compppgpyuted the interpolating polynomial P2(x) for (-1,1), (0,2) and (1,5) as follows: 15 Px()=−− xx (1)2(1)(1)(1) x++++ x− ++ x x 2 22 zThen, we may use P2(x) to find other values: 15 P (3)=−− 3(3 1) 2(3+++++ 1)(3− 1)++ (3 1)3=− 3 16+ 30= 17 2 22 15 P (−= 2) ( − 2)(( −−− 2) 1) 2(( −+ 2) 1)(( −−+ 2) 1) (( −+−=−+= 2) 1)( 2) 3 6 5 2 2 22 15 P (0.5)=−−+−++=−++= 0.5(0.5 1) 2(0.5 1)(0.5 1) (0.5 1)0.5 0.125 1.5 1.875 3.25 2 22 18 Lagrange Polynomials: 9/14 zUse a polynomial to evaluate x y the sin() function. i i zIt is sufficient to restrict the 0.0 0.0 0.3 0.29552021 range to about [0,1.5]. A 0.6 0.5646425 table of (xi,yi)’s is generated.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    67 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us