You are on page 1of 18
Eight Homework on NumComp April 7, 2009 \ Review questions, 7.1-7.30 (no credit). cS era bey fe a1 7/ W- et aa Lod Section 2 4/7/09 Numerical Computing Homework #8 7.5 page 335 ae 7:1 page 336 Zs Computer project 7.5 page 337 {0 ce Computer project 7.7 page 337 Computer project 7.8 (a-d) page 337 Extra eredit 20% Computer Project 7.8 (¢-g) page 337 7.10 page 336 Extra credit 20% 7.12 page 336 Extra eredit 20% Section 2 7 — Numerical Computing 4/7/09 Homework #8 Eight Homework on NumComp April 7, 2009 Review questions, 7.1-7.30 (no credit). 28 1. 7.5 page 335 GO a.) Determine the polynomial interpolant to the data: ti 2 3 4 y [at 29 65 125 using the monomial basis. Ax=y 1 tt yay oy 1 & & @lln|_ |x 1 ty 03 3|}%3}~ |¥3 A ity tp ag)itel bs do. 2 14 i 12 4 8 }/*2}_] 29 1 309 27))%3) "| 65 14 16 641 b%4 125. Xy +X +X3 4x4 =11 xy t Dy + 4ixg + Bry = 29 y+ 3xq + 9x, + 27x4 = 65 ay + Ag + 16x3 + 64x, = 125 Solving the system of linear equations: y(t) = 03 + 30? +245 Numerical Computing Section 2 Homework #8 4/7/09 b.) Determine the Lagrange polynomial interpolant to the same data and show that the resulting polynomial is equivalent to that obtained in part a. t |i [2 3 4 ul 29 65 25am Pn—a(t) = Vals (€) + Yala) + + Ynln(O) palt) = yalr(t) + yala(t) + ysls(O) + vals (-b)t-t)(e-t) _ (- 2-3) - 4) 4 = @rayG=iG-s)~ d-ad-9a—H) (@-S5e+ 6-4) 8 —40?- Se? 4200+ 6-24 _ 8-90? + 26¢- 24 6 = -6 ~ -6 (e-t)t-t)(E-4) _ €-DE-IE-4 8O-@ rae t= &) @-N@-Ne-4) _ (= 404 3C-4) _ 40? — ae? + 16t + 3-12 _ 8 — Be? + 19e- 12 2 7 2 7 2 (= t)e-t)t-t) _ €-DE-2e-4) 8O = Ga HG—t) G-DE-DE=H 3 3t+ 2 8 — 4¢? — 3¢? + 12t + 2t-8 7t? + 14t —8 =2 =2 —2 (@-t)E-b)t-t) _ €-DC-2E-3) WO = Gea G6) E=DE=DE=3) _(@ = 3t+2)(¢-3) _ 8-30? 30? +9¢4+2t-6 _ 8-60? + 114-6 = 6 OG Numerical Computing Section 2 Homework #8 4/7/03 pst) = yl (0) + yala(O) + ysls(8) + Ye) t3 — 9t? + 26t — 24 ¢3 — 8t? + 19¢ — 12) 3-70? + 14¢-8 pa(t) = 11 (LOPE 4266 2A) | og (EA BE HIT) | og (Eo +8 6 z =2 3-6? + 11t-6 4125/9 FA’ 6 1 1 1 1 1) 54 29(2) 0 465(L) 3 1) os = ps n(S)e +29(5)¢ o +125(2)e By 6 u(-3) 2 +29(- see 6(-3 J) e+ 125 (-2)e = 32 u(@ 2+ 29(P)ee+ a(S Se + 125(2 2) pe = 20 i & e429 Ge +65 (Se +125 @) =5 pa(t) = t3 + 3t? +2045 ¢.) Compute the Newton polynomial interpolant to the same data using each of the three methods in section 7.3.3 (triangular matrix, incremental interpolation, and divided differences) and show that each produces the same result as the previous two methods. ti 2 3 4 | y |i 29 65 125 | Triangular Matrix: oe 2 0 ay pr 1 (2-4) 0 0 x2] _ ly 1 G@-4) (-4)(-t) 0 X31 = lys Tit) (4-Be-b) -tG-f)(t,-t,) |bal by 1 0 0 0 1 @-1) 0 ° Pele 1 G-1) @G-DEGB-2) 0 3) = |y3 1 4-1) 4-4-2) @-)G-24-3) Jbl by. 100 E 22 iE i | 1 2 2 Offs 136 al Laas. — ‘Numerical Computing Section 2 Homework #8 4/7/09 x1 + Ox, + 0x5 + Ox, = 11 Hy +2, + Oxy + Ox, = 29 Hy + xy + 2xy + Oxy = 65 q+ 3x2 + 6x3 + 6x4 = 125 Solving the system of linear equations: MSM my =18 xy=9 x%y=1 Pn—a(t) = xy + a(t — th) + x3(t — ty) (C= te) + + x(t (tf) (Ctra) p3(t) = xy + x2(€— ty) +43 (t — G)(t- &) + x(t H(t te)(t- t) p(t) = 11 + 18(¢ - 1) + 9(¢ — 1) - 2) + 1 — 1) - 2) - 3) ps(t) = 11 + 18¢ - 18 + 9(¢? — 3t + 2) + 1(¢ — 6e? + 11¢ - 6) p(t) = 11 + 18¢ — 18 + 9(t? — 3¢ + 2) + 1(¢? - 6e? + 11¢ - 6) pa(t) = t8 + 9t? — 6t? + 18t + 11t — 27¢ + 11+ 18- 18-6 p3(t) = ¢? + 3t? +2645 Incremental Interpolation: t fi 2 sme 4 iL 29 65 125 Pyar) = PCO) + X17} O — Yin PiGies) x ” Tysa(tiea) pm) =m = 11 Pr(te) Pott) = p(t) + xoma(t) = pO) + ame 29-11 1 (¢-1) = 11+ 18¢- 18 = 18t-7 ‘Numerical Computing Section 2 Homework #8 4/7/09 3 — Pats) PaCO) = PalO) + x31 (0 = pal + wal 8(3) +7 =18t-7+ D 18 (-E~ 2) = 18-7 + (3042) = 18t—7 + 9¢?— 27+ 18 = 90? -9¢ +11 Pal = aC0) + xara) = pa + AE (0) Ya = Plt) pi) Ee moO 2 125~ (942-941) ot! H+ +E DGS Ny at) CCE ta V(E~ ts) 2 912 — 96-4 11 OOOO 41D ye ay ¢-3) @ D4 = 2)(4 ) 6 90? - 90411 +g — 6t? + 11t- 6) 90? —9t + 11+ 03 —6t? +11t-6 pa(t) = 09 + 30? + 2045 _ Numerical Computing peatone| Homework #8 4/7/09 Divided Differences: tii [2 3 4 im 29 om 125 ft tt = Meta tel— Flt ty PCE) = Fles(O + fle tala) + feta tala + fle totortaa(O flGl=14 fltel=29 flts]=65 — f[bs) = 125 flex] = fled] _ 29-11 _ flat) = Ld. BS = 8 - 65-29 fitz t4)= DA). S-F 2 36 im Fits ts] by — fite,tal — ftv ta] _ 36-18 _ Filta, tarts] = aan eeas aioe 9 Fletastg = flentsl —fllntal _ 60-36 _ uot 4-2 _ Fite ts ts] - fltr te, ~ tat Fits try ta, ta] pO) = Fleder (© + ft telra(©) + fits, ta, talms(t) + Fler toy ta, telita(O. p(t) = 11 + 18(t — ty) + 9(¢ = f(t - te) +16 - 4) t)(t- 3) p(t) = 11 + 18(t - 1) + 9(t- 1) - 2) + 1 - IE 2)(¢- 3) p(t) = 11+ 18¢ — 18 + 9¢? —27¢ + 18 +t? — 6t? + 116-6 p(t) = +30 +2¢4+5 Numerical Computing Section 2 Homework #8 4/7/09 2. 7.11 page 336 Prove that the formula using divided differences is Section 7.3.3, ZG 5 45 = Fits, tay, ti] indeed gives the coefficient of the jth basis function in the Newton polynomial interpolant. m0) = (C- AN(t=t) (C=) my (t) = x(t — H(t — &) ... (t- Ae tarts, ti] — Ft tay otha] ty tar, Fate foi Fleas tans)" = Flee tas mt) — 1) + ft torte] Sts: tar ost] — fte ta, Got Other formula: f[t2, ts, ..,t)] = Combined: ft, te, ,t](t — th) + Flt te [este F tartar me ti) (Gj — t:)(Gj — te) + fenton nota) G ~ te) = ft tas noob] — Fite tr oerty-a] Stas tas rtf) (Gj — GY — 2) + fan tar oneal (Gy ~ ta) + Flite to, thal = f[tseter nt] Faster mrt] = f tartar ms ty](ty ~ te)G — te) t ftastay —-»ty-a)(G — te) + Flterts, tha] ie Starts, 0, tj] — Fits tay mn tyaa] Other formula: [t3,t4,..,t) aoe tj — ta ‘Combined: Fle tarot] (ty ~ x) ~ 2) + Flats tyaal ty ~ 2) + Fllartar ns anes Numerical Computing Section 2 Homework #8, 4/7/09 AA BG ~ 8) + Alta atesTG 1) + lett) = eet tte Fle tarot ~ 8) = #59 — 6) + flat ta] G = YEG ~ 85) + Flt ata] — 0) = Altrts net] ~ fltrta oes] Fates ot ](G = NG ~ YG — a) + Fearon toa] (G — EYE ~ 5) + Fortran aa](G ~ ts) + ftstar esta] ® fetes] Flea tarot] = Flt tar ost ]CG 5G — ta) (eta) + Flt -s]CG ~f5)(6 — ta) + State st a](G ~ 63) + Fert nti Using this term and following the pattern, we can predict the next term will look like this: tort = Attar GGG ~ NC ~ EY ~ YG =) + (y= YG - Flat oth al(G ~ 6) 4) + Flets + flew e)G-%) pe ‘The next term can be predicted using the simplified equation: 4) =f [tartar ost) (G) + ltt, (6) + Flea taste} 2G) + Flt onrtpadt-a(t) + fMtartes oe tyaal Which can be further simplified to: xy = F [tartar mt] for the coefficient term if we extract out the 7(t) = (t — t)(t — tz) ...(t — tj) term. ‘This process needs to be repeated ‘j" number of times in order to calculate the coefficient for the jth term using the equation: Numerical Computing Homework #8 3. Computer project 7.5 page 337 An experiment produced the following data: Section 2 4/7/09 fi [0.0 03 1.0 6.0 Ly 0.0 1.6 2.0 2.0 7.0 15 We wish to interpolate the data with a smooth curve for y for values of ¢ between the point at which the measurements were taken. in the hope of obtaining reasonable values a) Using any method you like, determine the polynomial of degree five that interpolates the given data, and make a smooth plot of it over the range 0 < ¢ <9. ,) Similarly, determine a cubic spline that interpolates the given data, and make a smooth. plot of it over the same range. Interpolation — Newton — Cubic Spline | c.) Which interpolant seems to give more reasonable values between the given data points? Can you explain why each curve behaves the way it does? The cubie spline gives more reasonable values between the given data points. This is because the degree of the polynomial (degree five) is large enough that a big gap between the points (between 1 and 6) will cause it to wiggle in this area and project a curve that has no basis on the given data points. The polynomial function also exhibits wiggle between 7 and 9. In order to Numerical Computing Section 2 Homework #8 4/7/09 counteract this, the given points need to be spaced closer together as they diverge from the middle. However, the cubic spline is resistant to this type of wiggle, since it is composed of piecewise third-order polynomials, and projects a curve that follows the trend the data in a seemingly much more accurate way. .) Might piecewise liner interpolation be a better choice for this particular data? Why? Piecewise linear interpolation would most likely not be a better choice for this data because of the large gap between the x-values of 1 and 6, Though the other curves follow an almost linear trend between all the other points, itis very unlikely that the data propagates linearly from the x- values of 1 and 6. The cubic spline projects the most probable trend that the data might follow between these points, making piecewise linear interpolation not the preferred choice, sHorework #8 SComputer Problen 7.5 sparta.) format. long 1.0, 6.0, 7-0, 9.07 6, 2-0, 2.0, 1.5, 0.01; Higure(1); scatter (x, Yi Ae[K'. AS, x14, KAA, XN AL, xt.40 disp(™m5"); CoATEA\ ANY") 12907 yee (1, 1)#2.5 A0(3,1) #2.°34C (4,1) 42.9240 (5, 1) #24016, 1) 7 hold on Plot (2,y,"x") Le ("Tnterpolation') xlabel ("x") ylabel (*y") Seart b.) spline(x,y) Linspace (0, 9,100) ; hold on plot (xx, ppval (68, 2x) ,'=")7 hegend ("Original Values", "N ‘The gamma function is defined by 4, Computer project 7.7 page 337 Numerical Computing Homework #8 T@)= [ etentdt, x>0 0 For an integer argument n, the gamma function has the value So Section 2 4/7/09 T(r) ==! so interpolating the data points th fi 2 3 4 5 _ y it i 2 6 24 should yield an approximation to the gamma function over the given range. a.) Compute the polynomial of degree four that interpolates these five data points. Plot the resulting polynomial as well as the corresponding values given by the built-in gamma function over the domain [1,5]. b.) Use a cubic spline routine to interpolate the same data and again plot the resulting curve along with the built-in gamma function. 25 15 10 Interpolation Original Values | —— Newton Cubie Spline = Gamma 45 5 Numerical Computing Section 2 Homework #8 4/7/08 a.) Which of these two interpolants is more accurate over most of the domain? ‘Newton is more accurate to the gamma function for most of the domain. b.) Which of the two interpolants is more accurate between 1 and 2? ‘The cubic spline is closest to the gamma function between | and 2. However, after 2, Newton is more accurate over the remaining portion of the domain. aHonework: #8 omputer Probl 2,3, 4, 5) 1, 2, 6 24)e figure(2); scatter (x,y) 7 Retwt M4, x83, xt KYL 7.001) disp (*n-4"); CratSA\(ATty") ze(1:0.1:5)7 YeC(1)1) #2. 9440 (2,1) #2. 9340 (3, 1) 12.9240 (4,1) #24C(5,/ 1) hold on plot (zry,'r"); title (*Interpolat xlabel ("x") ylabel('y") xe, 2, 3, 4) 51 ye(L, 1, 2, 6, 241; cs = spline(x,y) xx = Linspace{t, 5,100) hold on Plot (xx, ppval (cs, xxx) ,'~") xe(L: 1:5] y= GRIAIA (x) Plot (x,y,"g") Legend( "original Va 1 'Newton* ubic Spline", "Gazma") Numerical Computing Section 2 Homework #8 4/7/09 5. Computer project 7.8 (a-d) page 337 Consider the following population data for the United States: — [Year Population BQ. 1900 76,212,168 oo 1910 92,228,496 1920 106,021,537 1930 [123,202,604 1940 132,164,569 [1950 151,325,798 1960 179,323,175 1970 203,302,031 1980 226,542,199 ‘There is a unique polynomial of degree eight that interpolates these nine data points, but of course that polynomial can be represented in many different ways. Consider the following possible sets of basic functions 0 ,(t), j = : 1. OQ = tt 2. 0,(€) = (t- 1900) 3. Oj(t) = (t- 1940)/-1 4, 0)(O) = ((e— 1940) /40)/-2 a, For each of these four sets of basis functions, generate the corresponding Vandermonde matrix and compute its condition number using a library routine for condition estimation. How do the condition numbers compare? Explain your results. Basis func Condition number Té6o 3.237700638869351¢+027 [2 #(t)=(e-1900)"* | 7,406784635479568+017 | 3 pjt}=(t-1940)* 3,718096156666575e+014 1.605443700478669e+003 ‘The fourth function has a far lower condition number than the other three functions. This is because the year values are shifted and scaled in a manner that keeps them from growing incredibly large when they are taken to the higher powers in the 8" degree polynomial. b. Using the best-conditioned b: Numerical Computing Section 2 - Homework #8 4/7/03 found in part a, compute the polynomial interpolant to the population data, Plot the resulting polynomial, using Horner’s nested evaluation scheme to evaluate the polynomial at one-year intervals to obtain a smooth curve. Also plot the original data points on the same graph. c. Use a routine for Hermite cubic interpolation, such as pehip from MatLab or Netlib, to compute a monotone Hermite cubic interpolant to the population data and again plot the resulting curve on the same graph. 4. Use a cubic spline routine to interpolate the population data and again plot the resulting curve coulla't Fige oot ax panne erner 'S oneuriny [ Hab oo causing 22) potynomrat be H * be Sligh ly off "| @p 16 1.44 "3 ; —— pel Polynomial —— pehip | spline 'e90. 1900 7810 1420 18301690 1960 1960 1970 1980 1000 Numerical Computing Section 2 Homework #8, 4/7/03 MatLab Output: he Ae+008 * on 1.371645690000000 cocbieients fund fer Fh deswe p .s7ornsze0s65669 LOZmBS478574 1873286969780383 2748478888888 -2350TABKTOTTS gk be BEKO 0292497777760 tyaomrol 1 4 emer beeurlag -SU5IBDZ351746018 ale 1.008838403030661 ork $4 ter Problem t=[1900; 1910; 1920; 1930; 1940;1950; 1960; 1970; 1980); yr (76212168; 92228496; 106021537; 123202624; 132164569; 151325798; 179323175; 203302031; 226542199}; scatter (t,y); i=l; while i x = (1900; 1910; 1920; 1930; 1940;1950; 1960; 1970; 1980); y = (76212168; 92228496; 106021537;123202624; 132164569; 151325798; 179323175; 203302031; 226542199); t = 1900:10:19807 plot (t, [pehip(x,y,t)# spline(x,y,t)]) legend("data*, "Polynomial", "pchip', 'splin Numerical Computing Section 2 Homework #8 4/7/03 6. Extra eredit 20% Computer Project 7.8 (¢-g) page 337 ce. Extrapolate the population to 1990 using each of the polynomial, Hermite cubic, and cubic spline interpolants and compute the values obtained, How close are these to the true value of 248,709,873 according to the 1990 census? x 10° 2.4} al 2h | 18, Polynomial | joc Actual Value: 248,709,873 1990 Polynomial Value: 125,648,559 Rel. Error for Polynomial: 49.48% 1990 Hermite Value: 226,542,199 Rel. Error for Polynomial: 8.913% 1990 Spline Value: 256,915,298 Rel. Error for Polynomial: 3.299%

You might also like