APPROXIMATE INTEGRATION. Introduction We hve seen tht there re functions whose nti-derivtives cnnot be expressed in closed form. For these resons ny definite integrl involving these integrnds cnnot be determined in n exct mnner. Alterntively, function my only be determined by scientific experiment in the form of tbles of dt. In this sitution there my be no formul for the function. In these cses we cn find pproximte vlues of definite integrls. We hve lredy seen bsic pproch to this, nmely Riemnn sums. Any Riemnn sum could be used s n pproximtion to the ctul integrl. Tht is if we divide [, b] into n subintervls of equl length x = b n then we hve f(x)dx f(x i ) x i= where x i is ny point in the i th subintervl [x i, x i ]. If we choose x i to be the left endpoint of the intervl, x i = x i then () f(x)dx L n = f(x i ) x. A If f(x), the integrl represents n re nd () will be n pproximtion of this re by n rectngles. If insted we choose the right endpoint s x i, so tht x i = x i, then () f(x)dx R n = f(x i ) x A The pproximtions L n nd R n defined by equtions () nd () re clled (unsurprisingly) the left endpoint pproximtion nd right endpoint pproximtion respectively. i= i=. Other Approximtions These re not the only pproximtions possible. If one chose x i to be the midpoint x i of the subintervl [x i, x i ] we produce the midpoint pproximtion M n which will perform better thn L n or R n. Proposition.. MidPoint Rule A f(x)dx M n = where x = b n nd x i = (x i + x i ) f( x i ) x i=
APPROXIMATE INTEGRATION Another pproximtion tht is more ccurte thn L n or R n is the Trpezoidl Rule which cn be found by verging equtions () nd (): [ f(x)dx n f(x i ) x + i= ] f(x i ) x i= = x [ n ] f(x i ) + f(x i ) = x [(f(x ) + f(x )) + (f(x ) + f(x )) +... + (f(x n ) + f(x n ))] = x [f(x ) + f(x ) + f(x ) +... + f(x n ) + f(x n )] This pproch cn be summrized s the following formul Proposition.. Trpezoidl Rule [ ] b f(x)dx T n = x n f(x ) + f(x i ) + f(x n ) where x = b x nd x i = + i x For f(x) the nme of the Trpezoidl rule becomes pprent if one drws the sums for prticulr function; we re no longer dding rectngles, but trpezoids over ech subintervl with the re of the i th trpezoid: ( ) f(xi + f(x i ) x = x [f(x i ) + f(x i )]. Adding up the re of ech trpezoids we recover the bove formul. i= Exmple.3. For n = 5, evlute the integrl () the Trpezoidl Rule () the Midpoint rule xdx using i= Proof. () Plugging in n = 5, = nd b = x = b x Trpezoidl rule produces = 5 =. nd the x dx T 5 =. (f() + f(.) + f(.4) + f(.6) + f(.8) + f()) ( =. +. +.4 +.6 +.8 + ).695635 () Averging the six points, we hve x dx M 5 = x[f(.) + f(.3) + f(.5) + f(.7) + f(.9)] = ( 5. +.3 +.5 +.7 + ).9.6998
APPROXIMATE INTEGRATION 3 3. Error Bounds This exmple ws delibertely chosen so tht its exct vlue could be computed, nd comprison of ccurcy could be drwn between the trpezoidl nd midpoint rules. The Fundmentl Theorem of clculus implies x dx = ln x] = ln =.69347... The error in using n pproximtion is defined to be the mount tht must be dded to mke the pproximtion equl the exct vlue. From exmple, we my compute the errors for n=5 from the trpezoidl nd midpoint rule to be More generlly, these re E T = E T.488, E M.39. f(x)dx T n, E M = f(x)dx M n. To compre the ccurcy of ech of L n, R n, M n nd T n consider the following tbles for n = 5,, nd n L n R n T n M n 5.745635.645635.695635.6998.7877.66877.69377.69835.7583.6883.69333.69369 n E L E R E T E M 5.5488.475.488.39.564.4376.64.3.656.344.56.78 From this tble, one cn mke the following observtions For ll of the methods, if we increse the vlue of n the pproximtion becomes more ccurte. Bewre lrge vlues of n due to the round-off error rising from the lrge number of rithmetic opertions. The error in the left nd right endpoint pproximtion hve opposite sign nd their error decresed by fctor of when n is doubled. The Trpezoidl nd Midpoint rule re better pproximtions thn the endpoint pproximtions. The trpezoidl nd midpoint rules hve error with opposite sign nd they decrese by rougly fctor of 4 by doubling n The mgnitude of the error for the Midpoint rule is roughly hlf the size of the error for the Trpezoidl rule. This lst fct cn be proven with elementry geometry - see Figure 5 in chpter 7.5 of the textbook. Any textbook in numericl nlysis will support these observtions. For exmple the fourth observtion rises from the fct tht n is involved in the sum, so tht (n) = 4n. As f (x) mesures how much the grph curves, the estimtes will depend on the size of the second derivtive of f(x)
4 APPROXIMATE INTEGRATION Proposition 3.. Error Bounds If f (x) K for x [, b], then the error bounds for the Trpezoidl nd Midpoint rule re respectively bounded by E T K(b )3 K(b )3 n, nd E M 4n Returning to exmple, we cn determine the error estimte for the Trpezoidl rule. With f(x) = x, f (x) = x nd f (x) = x, then since /x for x [, ] 3 f (x) = 3 =. x 3 Choosing K =, with =, b = nd n = 5 the error estimte from Proposition 3. will be ( )3 E T 5 = 5.6667 The ctul error for this exmple ws.488 <.6667, this shows it cn hppen tht the ctul error is substntilly less thn the upper bound for the error given by Proposition 3.. Exmple 3.. How lrge should n be chosen in order to gurntee the Trpezoidl nd Midpoint rule pproximte xdx to within.? Proof. Previously we sw tht f (x) for x [, ], thus tking K =, =, b = nd leving n rbitrry we hve Solving the inequlity for n, () 3 n. n > (.) n > (.6) 4.8 Choosing the lrger integer, n = 4 will ensure the desired ccurcy. Repeting this process for the Midpoint rule error bound 9 () 3 4n <. n > (.) Exmple 3.3. () Use the Midpoint Rule with n = to pproximte the integrl ex dx. () Give n upper bound for the error involved in this pproximtion. Proof. () Since =, b = nd n = we hve x =. nd the Midpoint rule yields e x dx x[f(.5) + f(.) +... + f(.85) + f(.95)] =.[e.5 + e.5 + e.65 + e.5 + e.5 + e.35 +e.45 + e.565 + e.75 + e.95 ].46393
APPROXIMATE INTEGRATION 5 () As f(x) = e x, then f (x) = xe x nd f (x) = ( + 4x)e x As x for ll x [, ] this implies f (x) = ( + 4x )e x 6e Choosing K = 6e, =, b =, nd n = in the error estimte of Proposition 3. the upper bound for the error is 6e() 3 4() = e 4.7 4. Simpson s Rule As n lterntive to using stright line segments to pproximte curve, we could use prbols insted. We divide the intervl [, b] into n subintervls of equl length h = x = b n, however now we require tht n is even. For ech consecutive pir of intervls we pproximte the curve y = f(x) by prbol. If y i = f(x i ) then P i (x i, y i ) is the point on the curve lying bove x i. Typiclly prbol psses through three consecutive points P i, P i+, nd P i+. For moment, let us suppose tht x = h, x = nd x = h, to mke our clcultion simpler. It is known tht the eqution of the prbol through P, P, nd P is of the form y = Ax + Bx + C nd the re under the prbol from x = h to x = h is h h (Ax + Bx + C)dx = h (Ax + C)dx ] h = [A x3 3 + Cx ) = (A h3 3 + Ch = h 3 (Ah + 6C). As the point psses through P ( h, y ), P (, y ), nd P (h, y ) implying thus y = A( h) + B( h) + C = Ah Bh + C y = C y = Ah + Bh + C y + 4y + y = Ah + 6C. Therefore we cn rewrite the re under the prbol s h 3 (y + 4y + y ) If we shift the prbol horizontlly we do not chnge the re under it. The re under the prbol through P, P 3, nd P 4 from x = x to x = x 4 is lso h 3 (y + 4y 3 + y 4 )
6 APPROXIMATE INTEGRATION Computing the res under ll of the prbols in this mnner nd dding the res together, A f(x)dx h 3 (y + 4y + y ) + h 3 (y + 4y 3 + y 4 ) +... + h 3 (y n + 4y n + y n ) = h 3 (y + 4y + y + 4y 3 + y 4 +... + y n + 4y n + y n While we only considered the cse where f(x), this pproch will work for ny continuous function f. This pproximtion is clled Simpson s Rule nd it is nmed fter the English mthemticin Thoms Simpson (7-76). It is importnt to remember the pttern of the coefficients, 4,, 4,, 4,,..., 4,, 4, ]. Proposition 4.. Simpson s Rule f(x)dx S n = x 3 [f(x ) + 4f(x ) + f(x ) + 4f(x 3 ) +... where n is even nd x = b x. +f(x n ) + 4f(x n ) + f(x n )] Exmple 4.. Use Simpson s Rule with n = to pproximte x dx Proof. Setting f(x) = /x, n =, = nd b = then x =. nd Simpson s rule yields x dx = [f() + 4f(.) + f(.) + 4f(.3) +...f(.8) + 4f(.9) + f()] x 3 =. ( 3 + 4. +. + 4.3 +.4 + 4.5 +.6 + 4.7 +.8 + 4.9 + ).6935 Compring with our previous exmple, it is cler tht Simpson s Rule gives significntly better pproximtion S.6935) to the true vlue of the integrl ln..69347). In fct, one cn prove tht the pproximtions in Simpson s Rule re weighted verges of those in the Trpezoidl nd Midpoint rules: S n = 3 T n + 3 M n It hs been mentioned tht often one must evlute n integrl even if one hs no explicit formul for y s function of x. Tht is, the function my be given grphiclly or s tble of vlues of collected dt. If the vlues do not chnge rpidly, the Trpezoidl rule or Simpson s rule cn be used to determine n pproximte vlue for ydx. Exmple 4.3. The following figure shows dt trffic on the link from the United Sttes to SWITCH the Swiss Acdemic nd Reserch Network on Februry, 998. Use Simpson s Rule to estimte the totl mount of dt trnsmitted on the link from midnight to noon on tht dy. Proof. As D(t) is mesured in megbits per second, we hve to convert the units for t from hours to seconds. Defining A(t) s the mount of dt trnsmitted by
APPROXIMATE INTEGRATION 7 Figure. Grph of D(t) dt throughput, mesured in Mb/s time t, where t is mesured in seconds, then A (t) = D(t). From the Net Chnge Theorem, the totl mount of dt trnsmitted by noon (t = x6 = 43, ) is A(43, ) = 43, D(t)dt. Estimting the vlues of D(t) t hourly intervls from the grph: t(hours) t(seconds) D(t) 3. 3, 6.7 7,.9 3, 8.7 4 4, 4.3 5 8,. 6, 6. 7 5,.3 8 8, 8.8 9 3, 4 5.7 36, 7. 39, 6 7.7 43, 7.9 Using Simpson s rule with n = nd t = 36 to estimte the integrl 43 D(t)dt t [D() + 4D(36) + D(7) +... + 4D(39, 6) + D(43, )] 3 36 [3.4(.7) + (.9) + 4(.7) + (.3) + 4(.) + (.) + 4(.3) 3 +(.8) + 4(5.7) + (7.) + 4(7.7) + 7.9] = 43, 88
8 APPROXIMATE INTEGRATION Thus the totl mount of dt trnsmitted from midnight to noon is 44, megbits or 44 gigbits. We cn compre the Simpson s rule nd the Midpoint rule, in the first tble, for the integrl xdx whise ctul vlue is.693478. In the second tble we cn compute the error for ech pproximtion. Notice tht E s decreses by fctor of bout 6 when n is doubled. This fct is consistent with the following error bound for Simpson s rule n M n S n 4.69989.6935453 8.696655.6934765 6.6935.69347 n M n S n 4.979.735 8.48663.47 6.97.3 Proposition 4.4. Error Bound for Simpson s Rule Suppose tht f (4) (x) K for x b. If E s is the error involved in using Simpson s Rule then E s K(b )5 8n 4 Exmple 4.5. How lrge should we tke n in order to gurntee tht the Simpson s Rule pproximtion for xdx is ccurte to within.? Proof. Since f(x) = /x then f(x) = 4/x 5 ; requiring x, /x nd so f (4) (x) = 4 4 x 5 Therefore we cn tke K = 4. Requiring tht the error is less thn. we choose n so tht This yields which gives n > 4() 5 8n 4 <. n 4 > 4 8(.) 4.75 6.4 Since n must be even, n = 8 will give us the ccurcy we require. This is pretty good compred to n = 9 for the midpoint rule nd n = 4 for the Trpezoidl rule. Exmple 4.6. () Use Simpson s Rule with n = to pproximte the integrl ex dx. () Estimte the error involved in this pproximtion.
Proof. APPROXIMATE INTEGRATION 9 () If n =, = nd b =, Simpson s rule gives e x dx x [f() + 4f(.) + f(.) +... + f(.8) + 4f(.9) + f()] 3 =. 3 [e + 4e. + e.4 + 4e.9 + e.6 + 4e.5 + e.36 +4e.49 + e.64 + 4e.8 + e ].4668 () The fourth derivtive of f(x) = e x is nd since x we hve f (4) (x) = ( + 48x + 6x 4 )e x ( + 48 + 6)e = 76e. Setting K = 76e, with =, b = nd n = the error is 76e() 5 8() 4.5 From this we know the correct nswer to three deciml plces is e x dx.463