LECTURE 7 Algorithms for Polynomial Interpolation We have thus far three algorithms for determining the polynomial interpolation of a given set of data.. Brute Force Method. Set and solve the following set of n + equations for the n + coeæcients. 2. Newton Form Method. Set P èxè a n x n + a n,x n, + æææ+ a x + a 0 a n èx 0 è n + a n, èx 0 è n, + æææ+ a x 0 + a 0 y 0 a n èx è n + a n, èx è n, + æææ+ a x + a 0 y a n èx n è n + a n, èx n è n, + æææ+ a x n + a 0 y n P èxè c 0 + c èx, x 0 è+c 2 èx, x 0 èèx, x è+æææ+ c n èx, x 0 èèx, x è æææèx, x n,è and use the following recursive formulae to determine the coeæcients c k : c k y k, P k,èx k è èx k, x 0 èèx k, x è æææèx k, x k,è P k èxè P k,èxè+c k èx, x 0 èèx, x è æææèx, x k,è 3. Lagrange Form Method. For k 0; ;:::; n compute the cardinal functions `kèxè and then set ny j0 j6k èx, x j è èx k, x j è èx, x 0 èèx, x è æææèx, x k,èèx, x k+è æææèx, x n è èx k, x 0 èèx k, x è æææèx k, x k,èèx k, x k+è æææèx k, x n è P èxè nx k0 y k`kèxè There is one more method that is, computationally, much more eæcient than any of the algorithms above. This is the so-called method of divided diæerences. Notation 7.. Let fèx i ;y i è j i 0;::: ;ng be an ordered set of n + data points, let x k ;x k+;::: ;x k+j be any set of j consecutive nodes and let P k èxè c k;0 + c k; èx, x k è+c k;2 èx, x k èèx, x k+è+æææ+ c k;j èx, x k èèx, x k+è æææèx, x k+j,2èèx, x k+j,è be the Newton form of the interpolation polynomial for fèx i ;y j è j i k;::: ;k+ jg. The divided diæerence is the highest order coeæcient c k;j of P k èxè. f ëx k ;x k+;::: ;x k+jë.
7. ALGORITHMS FOR POLYNOMIAL INTERPOLATION 2 Remark 7.2. Note that if we set k 0 then the divided diæerences f ëx 0 ;x ;x j ë are just the coeæcients c j appearing in the Newton of the interpolation polynomial for fèx i ;y i è j i 0;:::;ng : For in this case, the polynomials P j èxè P j,èxè+c j èx, x 0 èèx, x è æææèx, x j,è and P 0 èxè c k;0 + c k; èx, x 0 è+c k;2 èx, x 0 èèx, x è P 0 èxè c k;0 + c k; èx, x 0 è+c k;2 èx, x 0 èèx, x è+æææ æææ+ c 0;j èx, x 0 è æææèx, x j,è+æææ+ c 0;n èx, x 0 è æææèx, x n,è fëx 0 ë+f ëx 0 ;x ëèx, x 0 è+f ëx 0 ;x ;x 2 ëèx, x 0 èèx, x è+æææ æææ+ f ëx 0 ;x ;:::;x j ëèx, x 0 è æææèx, x j,è+æææ æææ+ f ëx 0 ;x ;:::;x n ëèx, x 0 è æææèx, x n,è c 0 + c èx, x 0 è+c 2k;2 èx, x 0 èèx, x è+æææ æææ+ c j èx, x 0 è æææèx, x j,è+::: æææ+ c n èx, x 0 è æææèx, x n,è Theorem 7.3. The divided diæerences satisfy the following recursion relations f ëx i ;x i+;::: ;x i+jë f ëx i+;x i+;::: ;x i+jë, f ëx i ;x i+;::: ;x i+j,ë Proof. It suæces to prove this for i 0 and j n: because for any other choice of i or j, we can always construct a new set of data fè~x k ; ~y k èèx i+k;y i+kè j k 0; ;:::;~n jg for which the relation f ë~x 0 ; ~x ;::: ;~x ~n ë f ë~x ;::: ;~x n ë, f ë~x ;:::;~x ~n,ë ~x ~n, ~x 0 is equivalent to the relation in the problem statement. Let P n,èxè be the polynomial of degree n, that interpolates the data at the ærst n data points fèx 0 ;y 0 è ;::: ;èx n,;y n,èg and let Q n,èxè bethe polynomial that interpolates the data at the last n data points fèx ;y è ;::: ;èx n ;y n èg. Then if we set then Qèx i è 8 é : Qèxè Q n,èxè+ x, x n èq n,èxè, P n,èxèè Q n,èx 0 è+ x0,xn èq n,èxè, P xn,x0 n,èxèè P n, èx 0 èy 0 ; if i 0 Q n,èx i è+ xi,xn èq n,èx i è, P xn,x0 n,èx i èè y i, xi,xn è0è y i ; if 0 éién xn,x0 Q n,èx n è+ xn,xn èq n,èx n è, P xn,x0 n,èx n èè y n ; if i n Therefore, Qèxè is the interpolation polynomial P èxè for the data fèx i ;y i è j i 0;:::;ng. Now the coeæcient of the highest power of x for P èxè is P èxè f ëx 0 ;:::;x n ëèx, x 0 è æææèx, x n è f ëx 0 ;::: ;x n ë x n + O, x n,æ while the coeæcient of the highest power of x for Qèxè will be Qèxè x, x n èèf ëx ;::: ;x n ëèx, x è æææèx, x n è, f ëx 0 ;::: ;x n,ëèx, x 0 è æææèx, x n,èè + O x n, x 0 f ëx ;::: ;x n ë, f ëx 0;:::;x n,ë x n,o,x n,æ Since the highest order coeæcients must agree we have f ëx 0 ;::: ;x n ë f ëx ;::: ;x n ë, f ëx 0 ;::: ;x n,ë,x n,æ
7. ALGORITHMS FOR POLYNOMIAL INTERPOLATION 3 Now consider how we might construct the interpolation polynomial using divided diæerences. Suppose P èxè is the interpolation polynomial for a problem with four data points x 0 ;x ;x 2 ;x 3.We then have P èxè c 0 + c èx, x 0 è+c 2 èx, x 0 èèx, x è+c 3 èx, x 0 èèx, x èèx, x 2 è fëx 0 ë+fëx 0 ;x ëèx, x 0 è+f ëx 0 ;x ;x 2 ëèx, x 0 èèx, x è+f ëx 0 ;x ;x 2 ;x 3 ëèx, x 0 èèx, x èèx, x 2 è Now according to the preceding theorem fëx 0 ;x ;x 2 ;x 3 ë fëx ;x 2 ;x 3 ë, f ëx 0 ;x ;x 2 ë x 3, x 0 fëx2 ;x 3 ë, f ëx ;x 2 ëë x 3, x 0 x 3, x èx 3, x 0 èèx 3, x è, èx 3, x 0 èèx, x 0 è èx 3, x 0 èèx 3, x è, èx 3, x 0 èèx, x 0 è, fëx ;x 2 ë, fëx 0 ;x ë x, x 0 fëx3 ë, fëx 2 ë, fëx 2ë, fëx ë x 3, x 2 x 2, x fëx2 ë, fëx ë, fëx ë, fëx 0 ë x, x 0 x 2, x y3, y 2, y 2, y x 3, x 2 x 2, x y2, y, y, y 0 x 2, x x, x 0 However, this is not how we'll want to compute divided diæerences èby breaking down the complicated fëx 0 ;:::;x i ë to the original dataè. Rather, we'll employ a bottoms up approach. For notational and calculational convenience, we'll set so that our recursion relations can be expressed a bit more succinctly as æ Step. Set F ëëi; 0ë fëx i ëy i F ëi; jë fëx i ;x i+;::: ;x i+jë fëx i ;x i+;::: ;x i+jë fëx i+;::: ;x i+jë, fëx i ;::: ;x i+jë F ëi +;j, ë, F ëi; j, ë F ëi; jë æ Step 2. Set æ Step 3. Set æ. æ Step n,. Set æ Step n. Set F ëi; ë F ëi; 2ë : fëi;::: ;n, ë : F ëi; 0ë y i ; i 0;:::;n F ëi +; 0ë, F ëi; 0ë x i+, x i ; i 0;::: ;n, F ë0;në: fëi +; ë, fëi; ë x i+2, x i ; i 0;::: ;n, 2 fëi +;n, 2ë, fëi; n, 2ë ; i 0; F ë;n, ë, F ë0;n, ë ;
æ For each i from 0 to n, set 7. ALGORITHMS FOR POLYNOMIAL INTERPOLATION 4 c i F ë0;ië fëx 0 ;x ;::: ;x i ë æ The Newton form of the interpolation polynomial will then be P èxè 0 nx c i @ i, Y i0 The following Maple code implements this algorithm. j0 èx, x j è A èinitialize array Fëi,0ë for i from 0 to n do Fëi,0ë : Yëië; èapply recursion relations for j from to n do for i from 0 to n-j do Fëi,jë : èfëi+,j-ë - Fëi,j-ëèèèXëi+jë - Xëiëè; èconstruct Newton form of interpolation polynomial p : Fë0,0ë; è Yë0ë; g : for i from to n do g : èx-xëi-ëè*g p : p + Fë0,ië*g; èidentify the total coefficient of each power of x for i from 0 to n do c : coeffèp,x,iè: c : evalfèc,3è: lprintè`coefficient of x to the`,i,`is`,cè: Suppose we implement this code on a test function like T èxè 2x 8, 0x 5, 20x, 50 ; setting up our data points in the following simple-minded way x i a + b, a y i T èx i è for various choices of n, and intervals ëa; bë. Surprisingly, we don't get consistent results. For example, for n 0, ëa; bëë,0; 0ë, we obtain P èxè è0:0èx 0+è0:0èx 9 +è2:0èx 8 +è0:0èx 7 +è0:0èx 6, è0:0èx 5 +è0:0èx 4 +è0:0èx 3 +è0:0èx 2 +è6:0 æ 0 5 èx +è:0 æ 0 è n i
7. ALGORITHMS FOR POLYNOMIAL INTERPOLATION 5 On the other hand, taking n 0, ëa; bëë,0:005; 0:005ë, we obtain P èxè,è2:8 æ 0 5 èx 0 +è,:4 æ 0 5 èx 9 + è827èx 8 + è4:3èx 7, è7:52èx 6, è0:0èx 5 +è2:3 æ 0,4 èx 4 +è: æ 0,5 èx 3 +è:6 æ 0,8 èx 2, è20:0èx, è50:0è Of course, such discrepancies can be traced to the æoating point errors in the numerical algorithm. The way to get around such inconsistencies is to take a three step approach. æ Carry out an interpolation in a region ëa; bë where the data is changing very rapidly to get a handle on the higher degree terms of P èxè. æ Carry out an interpolation in a region ëa; bë where the rate at which data is changing rather moderately to get a handle on the lower degree terms of P èxè. æ Look for a region where the high degree terms and the low degree terms have about the same inæuence to get a ænal interpolation for P èxè. Note, however, that the test regions described above need not be near the origin, nor can there sizes be predicted a priori. Consider, for example, what might be appropriate regions for interpolating the following polynomial h i T èxè 0,6 èx, 500è 5, x + 500