Lecture 3: Interpoltory Qudrture. Qudrture. The computtion of continuous lest squres pproximtions to f C[, b] required evlutions of the inner product f, φ j = fxφ jx dx, where φ j is polynomil bsis function for P n. Often such integrls my be difficult or impossible to evlute exctly, so our next chrge is to develop lgorithms tht pproximte such integrls quickly nd ccurtely. This field is known s qudrture, nme tht suggests the pproximtion of the re under curve by re of subtending qudrilterls..1. Interpoltory Qudrture with Prescribed Nodes. Given f C[, b], we seek pproximtions to the definite integrl fx dx. If p n P n interpoltes f t n + 1 points in [, b], then we might hope tht fx dx p n x dx. This pproch is known s interpoltory qudrture. Will such rules produce resonble estimte to the integrl? Of course, tht depends on properties of f nd the interpoltion points. When we interpolte t eqully spced points, the formuls tht result re clled Newton Cotes qudrture rules. You encountered the most bsic method for pproximting n integrl when you lerned clculus: the Riemnn integrl is motivted by pproximting the re under curve by the re of rectngles tht touch tht curve, which gives rough estimte tht becomes incresingly ccurte s the width of those rectngles shrinks. This mounts to pproximting the function f by piecewise constnt interpolnt, nd then computing the exct integrl of the interpolnt. When only one rectngle is used to pproximte the entire integrl, we hve the most simple Newton Cotes formul. This pproch cn be improved in two complementry wys: incresing the degree of the interpolting polynomil, nd reducing the width of the subintervls over which ech interpolting polynomil pplies. The first pproch leds to the trpezoid rule nd Simpson s rule; the second yields composite rules, where the integrl over [, b] is split into the sum of integrls over subintervls. In mny cses, the function f my be firly regulr over prt of the domin [, b], but then hve some region of rpid growth or oscilltion. We ultimtely seek qudrture softwre tht utomticlly detects such regions, ensuring tht sufficient function evlutions re performed there without requiring excessive effort on res where f is well-behved. Such dptive qudrture procedures, discussed briefly t the end of these notes, re essentil for prcticl problems..1.1 Trpezoid Rule. The term qudrture is used to distinguish the numericl pproximtion of definite integrl from the numericl solution of n ordinry differentil eqution, which is often clled numericl integrtion. Approximtion of double integrl is sometimes clled cubture. For more detils on the topic of interpoltory qudrture, see Süli nd Myers, Chpter 7, which hs guided mny spects of our presenttion here. 7 October 9 3-1 M. Embree, Rice University
The trpezoid rule is simple improvement over pproximting the integrl by the re of single rectngle. A liner interpolnt to f cn be constructed, requiring evlution of f t the intervl end points x = nd x = b, p 1 x = f + fb f b The integrl of p 1 pproximtes the integrl of f: fb f p 1 x dx = f + b [ ] b fb f = fx + b = b f + fb. In summry, Trpezoid Rule: fx dx b x. x dx [ 1 x ] b f + fb. The procedure behind the trpezoid rule is illustrted in the following picture, where the re pproximting the integrl is colored gry. 1 1 3.57119... trpezoid 73.53... exct 1 Error bound for the trpezoid rule. To derive n error bound, we simply integrte the interpoltion error bound developed in Lecture 11. Tht bound ensured tht for ech x [, b], there exists some ξ [, b] such tht fx p 1 x = 1 f ξx x b. Note tht ξ will vry with x, which we emphsize by writing ξx below. Integrting, we obtin fx dx p 1 x dx = 1 f ξxx x b dx 7 October 9 3- M. Embree, Rice University
= 1 f η x x b dx = 1 f η 1 3 1 b + 1 b 1 b3 = 1 1 f ηb 3 for some η [, b]. The second step follows from the men vlue theorem for integrls. We shll develop much more generl theory from which we cn derive this error bound, plus bounds for more complicted schemes, too, in Lecture 3b. Exmple: fx = e x cos x + sin x. Here we demonstrte the difference between the error for liner interpoltion of function, fx = e x cos x + sin x, between two points, x = nd x 1 = h, nd the trpezoid rule pplied to the sme intervl. Our theory predicts tht liner interpoltion will hve n Oh error s h, while the trpezoid rule hs Oh 3 error. in Liner Iterpoltion nd Associted Qudrture Error 1 1 Error 1 1 1 1 1 1 Error in Liner Interpoltion, Oh Error in Trpezoid Qudrture, Oh 3 1 1 1 Intervl width, h=b 1 3.1. Simpson s rule. We expect tht better ccurcy cn be ttined by replcing the trpezoid rule s liner interpolnt with higher degree polynomil interpolnt to f over [, b]. This will increse the number of times we must evlute f often very costly, but hopefully will significntly decrese the error. Indeed it does by n even greter mrgin thn we might expect. Simpson s rule follows from using qudrtic pproximtion tht interpoltes f t, b, nd the midpoint + b/. If we use the Newton form of the interpolnt with x =, x 1 = b, nd The men vlue theorem for integrls sttes tht if h, g C[, b] nd h does not chnge sign on [, b], then there exists some η [, b] such tht R b gtht dt = gη R b ht dt. The requirement tht h not chnge sign is essentil. For exmple, if gt = ht = t then R 1 gtht dt = R 1 1 1 t dt = /3, yet R 1 ht dt = R 1 t dt =, so for ll 1 1 η [ 1, 1], gη R 1 ht dt = R 1 gtht dt = /3. 1 1 7 October 9 3-3 M. Embree, Rice University
x = + b/, we obtin p x = f + fb f b x + f f1 + b + fb b x x b. Simpson s rule then pproximtes the integrl of f with the integrl of p : p x dx = p 1 x dx + f f1 + b + fb b x x b dx = b f + fb + f f1 + b + fb b 3 b = b f + f 1 + b + fb, where we hve used the fct tht the first two terms of p re identicl to the liner pproximtion p 1 used bove for the trpezoid rule. In summry: Simpson s Rule: fx dx b f + f 1 + b + fb. The picture below shows n ppliction of Simpson s rule on [, b] = [, 1]. 1 1 7.91331... Simpson 73.53... exct 1 Error bound for Simpson s rule. Simpson s rule enjoys remrkble feture: though it only pproximtes f by qudrtic, it integrtes ny cubic polynomil exctly! One cn verify this by directly pplying Simpson s rule to generic cubic polynomil. In Lecture 3b, we shll derive the tools to compute n error bound for Simpson s rule: fx dx p x dx = 1 9 b 5 5 f η It turns out tht Newton Cotes formuls bsed on pproximting f by n even-degree polynomil lwys exctly integrte polynomils one degree higher. 7 October 9 3- M. Embree, Rice University
for some η [, b]. We emphsize tht lthough Simpson s rule is exct for cubics, the interpolting polynomil we integrte relly is qudrtic. Though this should be cler from the discussion bove, you might find it helpful to see this grphiclly. Both plots below show cubic function f solid line nd its qudrtic interpolnt dshed line. On the left, the re under f is colored gry its re is the integrl we wish to compute. On the right, the re under the interpolnt is colored gry. Accounting re below the x xis s negtive, both integrls give n identicl vlue. It is remrkble tht this is the cse for ll cubics. 3.5 3.5 3 3.5.5 1.5 1.5 1 1.5.5.5.5 1 1 1.5 1 1 1.5 1 1 exct integrl Simpson s rule.1.3 Clenshw Curtis qudrture. To get fster convergence for fixed number of function evlutions, one might wish to increse the degree of the pproximting polynomil still further, then integrte tht high-degree polynomil. As we lerned in our study of polynomil interpoltion, the success of such n pproch depends significntly on the choice of the interpoltion points. For exmple, we would not expect to get n ccurte nswer by integrting high degree polynomil tht interpoltes Runge s function fx = x + 1 1 over uniformly spced points on [ 5, 5]. One expects to get better results by integrting the interpolnt to f t Chebyshev points. This procedure is known s Clenshw Curtis qudrture. The formuls get bit intricte, but the results re fntstic if f is smooth e.g., nlytic in region of the complex plne contining [, b]..1. Composite rules. As n lterntive to integrting high-degree polynomil, one cn pursue simpler pproch tht is often very effective: Brek the intervl [, b] into subintervls, nd pply the trpezoid rule or Simpson s rule on ech subintervl. Applying the trpezoid rule gives fx dx = n xj x j 1 fx dx n x j x j 1 fx j 1 + fx j. The stndrd implementtion ssumes tht f is evluted t uniformly spced points between See L. N. Trefethen, Is Guss Qudrture Better thn Clenshw Curtis?, SIAM Review 5 7 7. 7 October 9 3-5 M. Embree, Rice University
nd b, x j = + jh for j =,..., n nd h = b /n, giving the following fmous formultion: Composite Trpezoid: fx dx h n 1 f + f + jh + fb. Of course, one cn redily djust this rule to cope with irregulrly spced points. The error in the composite trpezoid rule cn be derived by summing up the error in ech ppliction of the trpezoid rule: fx dx h n 1 f + f + jh + fb = n 1 1 f η j x j x j 1 3 = h3 1 n f η j for η j [x j 1, x j ]. We cn simplify these f terms by noting tht 1 n n f η j is the verge of n vlues of f evluted t points in the intervl [, b]. Nturlly, this verge cnnot exceed the mximum or minimum vlue tht f ssumes on [, b], so there exist points ξ 1, ξ [, b] such tht f ξ 1 1 n n f η j f ξ. Thus the intermedite vlue theorem gurntees the existence of some η [, b] such tht f η = 1 n n f η j. The composite trpezoid error bound thus simplifies to fx dx h n 1 f + f + jh + fb = h 1 b f η. This error nlysis hs n importnt consequence: the error for the composite trpezoid rule is only Oh, not the Oh 3 we sw for the usul trpezoid rule in which cse b = h since n = 1. Similr nlysis cn be performed to derive the composite Simpson s rule. We now must ensure tht n is even, since ech intervl on which we pply the stndrd Simpson s rule hs width h. Simple lgebr leds to the formul Composite Simpson: fx dx h n/ f + 3 n/ 1 f+j 1h + f+jh + fb. Derivtion of the error formul for the composite Simpson s rule follows the sme strtegy s the nlysis of the composite trpezoid rule. One obtins fx dx h n/ f + 3 n/ 1 f + j 1h + f + jh + fb = h 1 b f η 7 October 9 3- M. Embree, Rice University
for some η [, b]. The illustrtions below compre the composite trpezoid nd Simpson s rules for the sme number of function evlutions. One cn see tht Simpson s rule, in this typicl cse, gives the better ccurcy. 1 1 73.335... composite trpezoid 73.53... exct 1 1 73.5751... composite Simpson 73.53... exct 1 1 Next we present MATLAB script implementing the composite trpezoid rule; Simpson s rule is strightforwrd modifiction tht is left s n exercise. To get the stndrd not composite trpezoid rule, cll trpezoid with N=1. function intf = trpezoidf,, b, N % Composite trpezoid rule to pproximte the integrl of f from to b. % Uses N+1 function evlutions N>1; h=b-/n. h = b-/n; intf = ; intf = fevlf,+fevlf,b/; for :N-1 intf = intf + fevlf,+j*h; end intf = intf*h; Puse moment for reflection. Suppose you re willing to evlute f fixed number of times. How cn you get the most bng for your buck? If f is smooth, rule bsed on high-order interpolnt such s Clenshw Curtis qudrture, or the Gussin qudrture rules we will present in few lectures re likely to give the best result. If f is not smooth e.g., with kinks, discontinuous derivtives, etc., then robust composite rule would be good option. A fmous specil cse: If the function f is sufficiently smooth nd is periodic with period b, then the trpezoid rule converges exponentilly. Adptive Qudrture. If f is continuous, we cn ttin rbitrrily high ccurcy with composite rules by tking the spcing between function evlutions, h, to be sufficiently smll. This might 7 October 9 3-7 M. Embree, Rice University
be necessry to resolve regions of rpid growth or oscilltion in f. If such regions only mke up smll proportion of the domin [, b], then uniformly reducing h over the entire intervl will be unnecessrily expensive. One wnts to concentrte function evlutions in the region where the function is the most ornery. Robust qudrture softwre djusts the vlue of h loclly to hndle such regions. To lern more bout such techniques, which re not foolproof, see W. Gnder nd W. Gutschi, Adptive qudrture revisited, BIT 11. MATLAB s qudrture routines. The MATLAB qudrture routine qud implements n dptive composite Simpson s rule. A different qudrture routine, qudl, uses Gussin qudrture, which we shll tlk bout few clsses from now. The following illustrtions show MATLAB s dptive qudrture rule t work. On the left, we hve function tht vries smoothly over most of the domin, but oscilltes wildly over 1% the region of interest. The plot on the right is histogrm of the number of function evlutions used by MATLAB s qud. Clerly, this routine uses mny more function evlutions in the region where the function oscilltes most rpidly qud identified this region itself; the user only supplies the region of integrtion [, b]. f x 1 1 x number of evlutions of fx 35 3 5 15 1 5 1 x This pper criticizes the routines qud nd qud tht were included in MATLAB version 5. In light of this nlysis MATLAB improved its softwre, essentilly incorporting the two routines suggested in this pper in version s the routines qud nd qudl. 7 October 9 3- M. Embree, Rice University