III Lecture on Numericl Integrtion File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9
1 Sttement of the Numericl Integrtion Problem In this lecture we consider the process of numericlly finding the vlue of the definite integrl: I = f(x)dx. The need for doing so rises in prcticl pplictions, becuse, in mny instnces f(x) is either not known explicitly or the vlue of I is difficult to determine. The process is clled Numericl Integrtion. We will ssume tht even though f(x) is not explicitly known, the vlues of f(x) t certin points in [, b] re known. Numericl Integrtion Problem Given f( ),f(x 1 ),...,f(x n ), where = <x 1 <x...< x n = b, compute n pproximte vlue of I = f(x)dx Numericl integrtion is very often referred to s numericl qudrture mening tht it is process of finding n re of squre whose re is equl to the re under curve. We would like to obtin qudrture formul of the following form: I = f(x)dx 0 f 0 + 1 f 1 +...+ n f n, where f i = f(x i ), i =0, 1,...,n, regiven,ndthecoefficients 0, 1,..., n re to be determined. Trpezoidl Rule Since f(x) is not explicitly known, the simplest thing to do will be to construct n interpolting polynomil for f(x) with,x 1,...x n s nodes nd integrte with the interpolting File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9
polynomil s the integrl. We shll us Lgrnge s Method to do this. The Lgrngin polynomils of different degrees will yield different rules of qudrture. Trpezoidl Rule f(x) Lgrnge Interpolting polynomil of degree 1 = Trpezoidl Rule In this cse, there re only two interpolting points:,x 1. X = X x 1 = b The Lgrnge interpolting polynomil P 1 (x) ofdegree1is: Then I = =x1 = f(x)dx x1 P 1 (x) =L 0 (x)f 0 + L 1 (x)f 1. [L 0 (x)f 0 + L 1 (x)f 1 ]dx Recll tht L 0 (x) = x x 1, nd L 1 (x) = x. x 1 x 1 So, I T = trpezoidl rule pproximtion of I is: I T = x1 [ x x1 f 0 + x x ] 0 f 1 dx x 1 x 1 = f x1 0 (x x 1 )dx + f 1 x 1 x 1 [ ] (x x1 ) x1 = f 0 x 1 Let x 1 = h. Thenwehve I T = + f 1 x 1 x1 (x )dx [ (x x0 ) Trpezoidl Rule ] x1 (b ) (f 0 + f 1 )= h (f()+f(b). = x 1 (f 0 + f 1 ). (.1) File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 3
.1 Error in Trpezoidl Rule Since the bove formul only gives crude pproximtion to the ctul vlue of the integrl, we need to sses the error. To obtin n error formul for this integrl pproximtion, recll tht the error formul for interpoltion of degree n is given by E n (x) = f (n+1) (ξ(x))ψ n (x), (n +1)! where Ψ n (x) =(x )(x x 1 )...(x x n ), nd ξ b( xo, b x n ). Since in cse of the Trpezoidl rule, n =1,wehve where Ψ 1 (x) =(x )(x x 1 ). E 1 (x) = f () (ξ(x))ψ 1 (x),! Integrting this formul we hve the following error formul for the Trpezoidl rule: E T (x) = x1 f () (ξ(x)) x1 (x )(x x 1 )dx =! f () (ξ(x)) Ψ 1 (x). (.)! We cn now simplify the bove formul by pplying the Weighted Men Vlue Theorem (WMT). Weighted Men Vlue Theorem (WMT Theorem) Let g(x) does not chnge sign in (x,x b ), then there exists constnt c between nd b such tht f(x)g(x)dx = f(c) g(x)dx. To pply the WMT to (.), we hve note tht the function Ψ 1 (x) =(x )(x x 1 )does not chnge sign over [,x 1 ], becuse, for x [,x 1 ], (x ) > 0nd(x x 1 ) < 0. Thus, Ψ 1 (x) is lwys negtive. File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 4
So, pplying the bove theorem to E T,withg(x) =Ψ(x) nd noting tht h = x 1,we obtin where <η<x 1. x1 =b = <η<b. f(x)dx = E T = f () (η)! x1 (x )(x x 1 )dx = h3 1 f (η), (.3) Trpezoidl Rule with Error Formul (b ) [f 0 + f 1 ] (b )3 f (η) = h h3 [f()+f(b)] 1 1 f (η), where Exctness of Trpezoidl Rule From the bove error formul it follows tht the Trpezoidl rule is exct only for stright lines. This is becuse, f (x) =0,whenf(x) is stright line, nd is non zero, whenever f(x) is of degree nd higher.. Geometricl Representtion of the Trpezoidl Rule Trpezoidl rule pproximtes the re under the curve y = f(x) from = to x 1 = b by the re of the trpezoid s shown below: (,f 0 ) C f y = f(x) D (x 1,f 1 ) A = h B = x 1 Figure 1: The Trpezoidl Rule. e File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 5
Note: The re of the trpezoid ABCD = Length of the bse verge height = h 1 (f 0 + f 1 )= h (f 0 + f 1 ). 3 Simpson s Rule If f(x) is pproximted by Lgrnge interpolting polynomil of degree nd then integrtion is tken over [, b] with the interpolting polynomil s integrnd, the result is Simpson s rule. f(x) Lgrnge Interpolting polynomil of degree = Simpson s Rule The three points of interpoltion in this cse re:,x 1, nd x. = x 1 x = b The Lgrngin interpolting polynomil P (x) =L 0 (x)f 0 + L 1 (x)f 1 + L (x)f. So, I = =x = f(x)dx x [L 0 (x)f 0 + L 1 (x)f 1 + L (x)f ]dx Now, L 0 (x) = (x x 1)(x x ) ( x 1 )( x ), L 1(x) = (x )(x x ) (x 1 )(x 1 x ), nd L (x) = (x )(x x 1 ) (x )(x x 1 ). Let h be the distnce between two consecutive points of interpoltion, ssumed to be eqully spced. Tht is, x 1 = h nd x x 1 = h. Substituting these expressions for L 0 (x),l 1 (x) ndl (x) nd tking integrtion, we obtin Simpson s Rule: I S = h 3 (f 0 +4f 1 + f )= h 3 (f()+4f 1 + f(b)) File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 6
Simpson s Rule I S = h 3 (f()+4f 1 + f(b)) 3.1 Error Formul for Simpson s Rule We hve used n = to derive Simpson s rule. So, the error formul for Simpson s Rule is given by E S = 1 f (3) (ξ(x))ψ (x)dx. 3! Since Ψ (x) =(x )(x x 1 )(x x ) does chnge sign in (,x ), we cn not pply WMT directly. In this cse, we will use slightly different technique. The following result will be used. Suppose tht f(x) chnges sign over (, b), however Ψ n (x) =(x )(x x 1 ) (x x n ) is such tht Ψ n (x) =0. Let x n+1 be nother point such tht Ψ n+1 (x) =(x x n+1 )Ψ(x) isofonesign 1 b in (, b). Then f(x)ψ n (x)dx = (n +)! f (n+) (η) Ψ n+1 (x)dx where, <η<b. In our cse n = nd we note tht x Ψ (x) = x (x )(x x 1 )(x x )dx =0. (Since x 1 = + x ). File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 7
Now choose x 3 = x 1, then Ψ 3 (x) =(x x 3 )Ψ (x) =(x x 1 )(x )(x x 1 )(x x )=(x x 1 ) (x )(x x ). Clerly, Ψ 3 (x) does not chnge sign over the intervl (,x ). So, ccording to the bove result, the error for Simpson s rule is given by f(x)dx = where <η<b E S = 1 x 4! f (4) (η) = 1 4 f (4) (η) = 1 4 f (4) (η) x ( 4 15 Ψ 3 (x) (x x 1 ) (x )(x x )dx ) h 5 = h5 90 f (4) (η). Simpson s Rule with Error Formul =x Exctness of Simpson s Formul f(x)dx = h = 3 (f 0 +4f 1 + f ) h5 90 f (4) (η) = b [ ( ) ] + b f()+4f + f(b) 6 ( ) 5 b 90 f (4) (η), It follows from the bove error formul tht Simpson s rule is exct for ll polynomils of degree less thn or equl to 3. (note tht if f(x) is polynomil of degree less thn equl to 3, then f 4 (x) =0, nd is nonzero for higher degree polynomils). If f(x) is polynomil of degree less thn or equl to 3. Simpson s rule is exct. File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 8
Exmple 3.1 Consider pproximting Simpson s Rule (SYMS). I Γ = Trp: I S =SYMS: 1 0 1 0 1 cos xdx 0.5(1 + 0.5403) = 0.770 cos dx 1 6 (1 + 4 cos(1 )+cos(1))=0.8418. Exct vlue 0.8415 (in 4-digit rithmetic). 4 Newton s-cotes Qudrture 0 cos xdx using both Trpezoidl Rule (TRAP) nd Trpezoidl Rule - Bsed on interpolting the function by polynomil of degree 1 with the nodes: = nd x 1 = b. I T = b (f()+f(b)). Simpson s Rule - Bsed on interpolting the function by polynomil of degree with the nodes: =, x 1 = + h = + b 1 I S = b 6 (f()+4f( + b )+f(b)). = + b, x = b. These two rules re specil cses of the Closed Newton-Cotes (CNC) rule. An n point closed Newton-Cotes rule hs the (n +1)nodes: x i = + i (b ),i=0, 1,,n. n File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 9
n =1 Trpezoidl Rule n = Simpson s Rule (Note tht CNC Rule includes the end points of the nodes) The open Newton-Cotes hs the (n +1)nodes which do not include the end points. x i = + i (b ),i=1,,,n. n + A well-known exmple of the n-point open Newton-Cotes rule is the midpoint rule (with n =0). Thus,the midpoint rule is bsed on interpoltion of f(x) with constnt function. The only node in this cse is: x 1 = + b. ( ) + b Thus I M = Midpoint Approximtion to the Integrl f(x)dx =(b )f. Error Formul for the Midpoint Rule: In this cse Ψ 0 (x) =x x 1 = x + b chnges sign in (, b). However, note tht if we = x 1,thenΨ 1 (x) =(x x 1 ) =(x + b ) is lwys of the sme sign. Thus, we cn show s in the cse of Simpson s rule tht,where<η<b Thus I M = E M = f (b )3 (η) 4 Midpoint Rule with Error Formul f(x)dx =(b )f( + b )+f (b )3 (η). 4 File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 10
Compring the error terms of I M nd I T, we esily see tht the midpoint rule is more ccurte thn the trpezoidl rule. Exmple 4.1 Apply the midpoint, trpezoidl nd Simpson s rule to I M = f(0.5) = e 0.5 =1.6487 I T = 1 (1 + e) =1.8591 I S = 1 ) (e 0 +4e 1 + e 1 =1.7189 6 I = 1 0 0 1 e x dx e x dx 1.7183 (correct to four deciml digits). 5 The Composite Rules Since the Trpezoidl nd Simpson s rules hve been derived with only 1 nd, subintervls, respectively, these rules re not likely to give ccurte results over lrge intervl. To obtin greter ccurcy, the ide then will be to subdivide the intervl [, b] into smller intervls, pply these qudrture formuls in ech of these smller intervls nd dd up the results to obtin more ccurte pproximtions. Let s divide [, b] into n equl subintervls s follows: = <x 1 <x...<x n 1 <x n = b. Let h = b = the length of ech of these subintervls. n Then =, x 1 = + h, x = +h,..., x n = b = + nh. 5.1 The Composite Trpezoidl Rule (CTR) To obtin the Composite Trpezoidl Rule over [, b] File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 11
Divide the intervl [, b] into n equl subintervls. Integrte f(x) over ech of those subintervls using the Trpezoidl rule for ech subintervl. Add the results. I CT = x1 = f(x)dx + x x 1 f(x)dx +...+ xn=b x n 1 f(x)dx = h (f 0 + f 1 )+ h (f 1 + f )+...+ h (f n 1 + f n ) ( f0 = h + f 1 + f +...+ f n 1 + f ) n. The Composite Trpezoidl Rule [ f0 I CT = h + f 1 + f +...+ f n 1 + f ] n = h [f()+f 1 +f + +f n 1 + f(b)]. 5. The Error Formul for Composite Trpezoidl Rule The error formul for CTR is obtined by dding the individul error terms of the trpezoidl rule in ech of the subintervls. Thus, the error formul for the composites trpezoidl rule, denoted by E C T in given by: ET C = h3 1 [f (η 1 )+f (η )+...+ f (η n )] Simplifiction of the Error Formul. To simplify the expression within the prenthesis, we need the following well-known result. File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 1
The Intermedite Vlue Theorem (IVT) If f(x) is continuous on [, b] ndk is number such tht f() <k<f(b), then there exists number c, < c < b with the property: f(c) =k. Applying the IVT nd remembering tht h = b, we get n where <η<b. E CT = nh3 1 f (η), where η 1 <η<η n. (b ) = n h n 1 f (b ) (η) = h f (η), 1 The Composite Trpezoidl Rule With Error Formul =xn = where <η<b. f(x)dx = h [ f0 + f 1 + f +...+ f ] n + b 1 h f (η) }{{}}{{} Composite Trpezoidl Rule Error 5.3 The Composite Simpson s Rule (CSR) Since Simpson s rule ws obtined with two subintervls, in order to derive the CSR, we divide the intervl [, b] intoeven number of subintervls, syn =m, wherem is positive integer nd then pply Simpson s rule in ech of those subintervls nd finlly, dd up the results. Obtining Composite Simpson s Rule File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 13
Divide the intervl [, b] inton =m equl subintervls: [,x ], [x,x 4 ]...,[x n,x n ] Integrte f(x) over ech of these subintervls using Simpson s rule Add the results. I CS = I CT = x = f(x)dx + x4 x f(x)dx +...+ =xn x n f(x)dx = h 3 [(f 0 +4f 1 + f )+(f +4f 3 + f 4 )+...+(f n +4f n 1 + f n )] = h 3 [(f 0 + f n )+4(f 1 + f 3 +...+ f n 1 )+(f + f 4 +...+ f n )]. =xn The Composite Simpson s Rule = f(x)dx h 3 [(f 0 + f n )+4(f 1 +...+ f n 1 )+(f +...+ f n )]. The Error in Composite Simpson s Rule The error in composite Simpson s Rule, denoted by E S C,isgivenby E S C = h5 90 where x i 1 <η i 1 <x i+1,i=1,,...,n 1. A Simplified Expression for the Error: f (4) (η 1 )+f (4) (η )+...+ f (4) f (4) (ηn, File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 14
By using IMT, it cn be shown tht there exists number η in (, b) such tht E CS = h5 90 n f (4) (η) = h5 180 (b ) f (4) (η) = h4 h 180 (b )f (4) (η). (Note tht n = b h ). The Composite Simpson s Rule with Error Term f(x)dx = h 3 [(f 0 + f n )+4(f 1 +...+ f n 1 )+(f +...+ f n )] h4 180 (b )f (4) (η) = h 3 [f()+f(b)+4(f 1 + + f n 1 )+(f + + f(n )] h4 }{{} 180 (b )f (4) (η) }{{} Composite Simpson s Rule Error x if 0 x 1 Exmple 5.1 Let f(x) = 1 x if 1 x 1 () Trpezoidl Rule over [0, 1] I T = 1 (f(0) + f(1)) = 1 (0 + 0) = 0 (b) Trpezoidl Rule over [ 0, 1 ] [ ] 1 nd, 1 : (c) Simpon s Rule over [0, 1] I S = 1 [ ( ) ] 1 f(0) + 4f + f(1) 3 = 1 ( ( ) ) 1 0+4 +0 = 1 3 3 () = 3 (f( 1 )+f(1) ) I CT = 1 4 (f(0) + f(1/)) + 1 4 = 1 (0+ 1 4 + 1 ) +0 = 1 4 (1) = 1 4 File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 15
5.4 Exmple (Appliction of the Error Formul) Determine h to pproximte 10 1 1 te dt t with n ccurcy of ɛ =10 3 using the Composite Trpezoidl rule. Recll tht the error formul in this cse is: E CT = b 1 h f (η). Let s now find the mximum vlue (in mgnitude) of E CT in the intervl [0.1, 10]. We then need to find f (η). Now, f(t) = 1 te (given) t nd f (t) = 1 te t ( 1 t + t +1 Thus, f is mximum when t =0.1 ) nd mx f (t) 1 = (100 + 0 + 1) = 1094.9 0.1 e0.1 ( ) 9.9 So, mximum vlue of EC T = h 1094.9. 1 Thus, to pproximte h with n ccurcy of ɛ =10 3, h hs to be such tht ( ) 9.9 h 1094.9 10 3. 1 Tht is, or h 1 10 3 1 9.9 1094.9 h 0.0105 10 7. File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 16
6 Romberg Integrtion The ide behind Romberg integrtion is to successfully use the Trpezoidl rule with incresing intervls nd stop s soon s two successive pproximtions gree to ech other by desired ccurcy. The key to do tht is to observe tht the successive pproximtions cn be generted recursively in terms of the previous pproximtions. Thus, Thus, R 11 = The Trpezoidl rule with 1 intervl = 1 (b )[f()+f(b)] (6.1) (Note tht h = b ) R 1 = The Trpezoidl rule with intervls = b [ ( f()+f(b)+f + b )] 4 (Note tht in this cse, h = b nd the points of subdivision re: =, x 1 = + b, nd x = b R 1 = 1 [ ( R 11 +(b )f + b )]. (6.) This formul immeditely cn be generlized. Denote R k1 = The Trpezoidl rule with k 1 intervls h k = b,k =1,, k 1 It cn be shown [Exercise] tht R k1 = 1 k R k 1,1 + h k 1 f( +(i 1)h k ),k =, 3, n (6.3) i=1 File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 17
Verify: k =. R 1 = 1 [R 11 + h 1 f( + h )] = 1 [ ( R 11 +(b )f + b )]. Furthermore, one cn show tht R 11 nd R 1 cn be combined to compute nother number R ; R 31 nd R 1 cn be combined to compute R 3 ; nd so on. The formul to do so is: R kj = R k,j 1 + R k,j 1 R k 1,j 1,k =, 3,...,n; j =,...,k (6.4) 4 j 1 1 Thus, R = R 1 + R 1 R 11 4 1 nd so on. = R 1 + R 1 R 11. 3 These numbers re clled Romberg numbers nd cn be rrnged in tble, similr to the divided difference tble, nd is known s The Romberg Tble. Romberg Tble R 11 R 1 R R 33 R 31..... R 3 R 4... R n1 R n R n3 R nn File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 18
6.1 Stopping Criterion Suppose tht we would like to compute cn be stopped s soon s f(x) with n ccurcy of ɛ, then the itertion Rnn R n 1,n 1 <ɛ. 6. Creting the Romberg Tble Since our ultimte interest is to obtin the digonl entries nd these entries cn be computed just out of two entries from the previous column, we cn compute the entries Romberg Tble in the following order of computtions. Compute R 11 nd R 1 using (6.1) nd (6.) Compute R out of R 11 nd R 1 using (6.4) Compute R 31 from (6.3) nd R 3 from (6.4) nd then combine R 3 with R to obtin R 33 using (6.4) gin. In generl, compute R k1 from (6.3) nd R k,k 1 from (6.4) nd then combine R k,k 1 with R k 1,k 1 to obtin R kk using (6.4) gin. Exmple 6.1 I = 1.5 1 x lnx with n =3 R 11 = 1 (1.5 1)[f(1) + f(1.5)] =.80741 R 1 = 1 (R 11 +(1.5 1)(f(1 + R = R.1 + R.1 R 1.1 4 1 1 =.1944945 1.5 1) )) =.015 File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 19
R 11 =0.80741 R 1 =0.0105 R =0.19453 R 31 =0.1944945 R 3 =0.19585 R 33 =0.19593 Exct vlue of I (up to five deciml figures) =0.1959 Adptive Qudrtive Adptive qudrture rule is wy to dptively djust the vlue of the step-size h such tht the error becomes less thn prescribed tolernce (sy ɛ). For the purpose of describing the ide of dptive qudrture rule, we will use Simpson s rule s our ground rule of pproximting the integrl. With the step-size h, tht is, with the points of subdivisions s, + h, ndb We hve the Simpson s rule pproximtion: X X X +h b IS h = h [f()+4f( + h)+f(b)] 3 nd Error ==ES h = hs 90 f (4) (η), where <η<b. Now let s use 4 intervls; tht is, this time the points of subdivision re:, + h,+ h, + 3h,b. X X X X X +h +h +h b 3 Then, using Compositive Simpson s rule with n = 4, tht is, with the length of ech subintervl h,wehve I h S = h 6 nd E h S = 1 ( ) h 5 f (4) (η), 16 90 [ f() + 4f ( + h ) + f(b) ] File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 0
were <η<b. Now the eqution is: how ell does I h S pproximte I over I h S? In this context, ssuming η η, it follows from the expressions of ES h nd E h S tht h I I 1 S I h 15 S I h S This is rther plesnt result; becuse it is esy to compute I h S I h, S suppose this quntity is denoted by δ. Then, if we choose h such tht δ =15ɛ, weseetht h E <ɛ. S File fclib/dttb/lecture-notes/numerical-inter03.tex /by EC, 3/14/008 t 15:11, version 9 1