s_3 Jnury 26, 217 1 Exercise 5.2.3 Apply composite Simpson s rule with m = 1, 2, 4 pnels to pproximte the integrls: () x 2 dx = 1 π/2 3, (b) cos(x) dx = 1, (c) e x dx = e 1, nd report the errors. () f(x) = x 2. For m = 1 we put h = (1 )/2 = 1/2, x =, x 1 = 1/2, x 2 = 1; y = f(x ) =, y 1 = f(x 1 ) = 1/4, y 2 = f(x 2 ) = 1. The pproximtion is then I h/3(y + 4y 1 + y 2 ) = ( + 4 1/4 + 1)/6 = 1/3. The error is thus. For m = 2 we hve h = (1 )/4 = 1/4, (x, x 1,..., x 4 ) = (, 1/4, 1/2, 3/4, 1), (y, y 1,..., y 4 ) = (, 1/16, 1/4, 9/16, 1). The pproximtion is then I h/3(y +4y 1 +2y 2 +4y 3 +y 4 ) = (+4 1/16+ 2 1/4 + 4 9/16 + 1)/12 = (1/4 + 2/4 + 9/4 + 4/4)/12 = 16/(3 4 4) = 1/3. The error is thus. One could continue with m = 3, but the error hs to be zero. Indeed, Simpson s rule is bsed on qudrtic interpoltion polynomils, which mens tht x 2 will be represented exctly by the interpolting polynomil nd the qudrture will be exct. (b) f(x) = cos(x) For m = 1 we put h = (π/2 )/2 = π/4, x =, x 1 = π/4, x 2 = π/2; y = f(x ) = 1, y 1 = f(x 1 ) = 1/ 2, y 2 = f(x 2 ) =. The pproximtion is then I h/3(y + 4y 1 + y 2 ) = (1 + 4/ 2 + ) π/12 1.227. The error is thus.227. For m = 2, h = π/8, (x,..., x 4 ) = (, π/8, π/4, 3π/8, π/2), (y,..., y 4 ) (1,.9238795, 1/ 2,.38268343, ). I h/3(y + 4y 1 + 2y 2 + 4y 3 + y 4 ) 1.135, giving the error.135. For m = 3, h = π/6, I 1.2631, errror.2631. (c) f(x) = exp(x) For m = 1 we put h = (1 )/2 = 1/2, x =, x 1 = 1/2, x 2 = 1; y = f(x ) = 1, y 1 = f(x 1 ) = e 1/2, y 2 = f(x 2 ) = e. The pproximtion is then I h/3(y + 4y 1 + y 2 ) = (1 + 4 e + e)/6 1.71886115. The error is thus 1.71886115 e + 1 5.79 1 4. For m = 2, h = 1/4, (x,..., x 4 ) = (, 1/4, 1/2, 3/4, 1),... I h/3(y + 4y 1 + 2y 2 + 4y 3 + y 4 ) 1.71831884192175, giving the error 3.7 1 5. For m = 3, h = 1/6, I 1.7182891699283, errror 7.34 1 6. 2 Exercise 5.2.11 Find the degree of precision of the following pproximtion for 1 f(x) dx: 1
First of ll, let us evlute the integrl of monomil x n, n : [ ] { x x n n+1 x=1, for odd n, dx = = n + 1 2/(n + 1), for even n. 1 x= 1 () f(1) + f( 1): Let us pply the qudrture to the monomil x n, n : { 1 n + ( 1) n, for odd n, = 2, for even n, Therefore the qudrture grees with the integrl for n =, 1 (nd ll odd n), nd its degree of precision is 1. (One could lso observe tht this is trpezoid qudrture on [ 1, 1], which is known to be exct for polynomils up to degree 1.) (b) 2/3[f(-1) + f() + f(1)]. We check the qudrture on monomils of incresing degree: 2, for n =, 2/3[( 1) n + n + ( 1) n ] =, for odd n, 4/3, for even n >, which grees with the integrl for n =, 1 (nd odd n). Thus degree of precision is 1. (c) We check the qudrture on monomils of incresing degree: [( 1/ 3) n + (1/ { 3) n, for odd n, ] = 2/3 n/2, for even n, which grees with the integrl for n =, 1, 2, 3 (nd odd n). Thus degree of precision is 3. (This is n exmple of Gussin qudrture, which re exct for polynomils of degree up to 2n 1 when n points re used.) 3 Exercise 5.2.16 Use the fct tht the error term of Boole s Rule (see Exercise 5.2.15) is proportionl to f (6) (c) to find the exct error term. We pply the qudrture to the monomil x 6, for which f (6) (c) 6!, for ll c. Thus 4h [ x x 6 7 dx = 7 ] x=4h x= = 47 h 7 7 = 2h 45 (7 6 + 32 h 6 + 12 (2h) 6 + 32 (3h) 6 + 7 (4h) 6 ) + C6! nd we re interested in finding C. In [1]: from sympy import * init_printing() h,c=symbols('h C') integrl = (4*h)**7/7 qudrture = 2*h/45*(32*h**6 + 12*(2*h)**6 + 32*(3*h)**6 + 7*(4*h)**6) simplify(integrl-qudrture) 2
Out[1]: Thus C = 128h 7 /(21 6!) = 8h 7 /945 128h7 21 4 Exercise 5.2.12 Wee need to find c 1, c 2, c 3 such tht the rule hs degree of precision greter thn one. To hve degree of precision we need tht f(x) dx c 1 f() + c 2 f(.5) + c 3 f(1) 1 dx = 1 = c 1 f() + c 2 f(.5) + c 3 f(1) = c 1 + c 2 + c 3. Similrly, for degree of precision 1 we need x dx = 1/2 = c 1 f() + c 2 f(.5) + c 3 f(1) =.5c 2 + c 3. Finlly, for degree of precision 2 we need x 2 dx = 1/3 = c 1 f() + c 2 f(.5) + c 3 f(1) =.25c 2 + c 3. This gives us 3 liner equtions in 3 unknowns, whose solution is c 1 = c 3 = 1/6, c 2 = 2/3. This is the sme s Simpson s rule. 5 Exercise 3b), Exm 8.216 L M [,b] f og T [,b] f være midpunkt og trpezoid kvdrturer med n = 1 pnel for funksjonen f på intervl [, b]. Feilestimtetene for disse kvdrturer er gitt v f(x) dx = M [,b] f + h3 24 f (c) + O(h 4 ), og f(x) dx = T [,b] f h3 12 f (c) + O(h 4 ), hvor c = ( + b)/2, og h = b. L oss definere en ny kvdrtur som Q [,b] f = αm [,b] f + βt [,b] f. Bestem verdiene α, β slik t : We hve f(x) dx = Q [,b] f + O(h 4 ). 3
nd therefore M [,b] f = T [,b] f = f(x) dx h3 24 f (c) + O(h 4 ), og f(x) dx + h3 12 f (c) + O(h 4 ), Q [,b] f = (α + β) As result we get system of equtions f(x) dx + (2β α) h3 24 + O(h4 ). α + β = 1, 2β α =. Thus α = 2/3, β = 1/3, which in fct gives us Simpson s rule: 6 Exercise 5.4.1 2 3 M [,b]f + 1 3 T [,b]f = 2h 3 f(c) + h 6 (f() + f(b)) = h [f() + 4f(c) + f(b)]. 6 Apply Adptive Qudrture by hnd, using the Trpezoid Rule with tolernce T OL =.5 to pproximte the integrls. Find the pproximtion error. () In this cse, f(x) = x 2, =, b = 1. We begin with n = 1 intervl, =, b = b. We will use S[, b] to denote the Trpezoid qudrture pplied on the intervl [, b]. c = ( + b)/2, S[, b] = ( 2 + 1 2 )/2 = 1/2, S[, c] = ( 2 + (1/2) 2 )/4 = 1/16, S[c, b] = ((1/2) 2 + 1 2 )/4 = 5/16. S[, b] S[, c] S[c, b] = 1/8 =.125 < 3.5 ((b )/(b )) =.15. Thus we stop with the pproximtion S[, c] + S[c, b] = 3/8 =.375 nd n error estimte (S[, b] S[, c] S[c, b])/3 = 1/24.417. The ctul integrtion error is x2 3/8 = 1/3 3/8 = 1/24. Our estimte is exct becuse f is constnt in this cse, thus the pproximte eqution (5.38) in the book is ctully exct. (b) f(x) = cos(x), =, b = π/2. S[, π/2] = (π/2) (1 + )/2 = π/2 1.578, S[, π/4] = (π/4) (1 + 1/ 2)/2.7854, S[π/4, π, 2] = (π/4) (1/ 2 + )/2.27768. S[, b] S[, c] S[c, b].5772 3.5 (π/2)/(π/2) =.15. Thus we need to split the intervl nd pply the dptive lgorithm recursively. S[, π/4] = (π/4) (1 + 1/ 2)/2.7854, S[, π/8] = (π/8) (1 + cos(π/8))/2.37775, S[π/8, π/4] = (π/8) (cos(π/8) + cos(π/4))/2.3224, S[, π/4] S[, π/8] S[π/8, π/4].8741 3.5 (π/4)/(π/2) =.75. Thus we need to split this intervl gin pply the dptive lgorithm recursively. S[, π/8] = (π/8) (1+cos(π/8))/2.37775, S[, π/16] = (π/16) (1+cos(π/16))/2.19446, S[π/16, π/8] = (π/16) (cos(π/16)+cos(π/8))/2.18699, S[, π/8] S[, π/16] S[π/16, π/8].37 < 3.5 (π/8)/(π/2) =.375. Thus we re done on the intervl [, π/8] with the pproximtion S[, π/16] + S[π/16, π/8].38145. 4
Let us look t the intervl [π/8, π/4] now. S[π/8, π/4] = (π/8) (cos(π/8) + cos(pi/4))/2.3224, S[π/8, 3π/16] = (π/16) (cos(π/8) + cos(3π/16))/2.17233, S[3π/16, π/4] = (π/16) (cos(3π/16) + cos(π/4))/2.1515, S[π/8, π/4] S[π/8, 3π/16] S[3π/16, π/4].314 < 3.5 (π/8)/(π/2) =.375. Thus we re done on the intervl [π/8, π/4] with the pproximtion S[π/8, 3π/16] + S[3π/16, π/4].32338. Let us look t the intervl [π/4, π/2] now. S[π/4, π/2] = (π/4) (cos(π/4) + cos(pi/2))/2.27768, S[π/4, 3π/8] = (π/8) (cos(π/4) + cos(3π/8))/2.21398, S[3π/8, π/2] = (π/8) (cos(3π/8) + cos(π/2))/2.7514, S[π/4, π/2] S[π/4, 3π/8] S[3π/8, π/2].1144 < 3.5 (π/4)/(π/2) =.75. Thus we re done on the intervl [π/4, π/2] with the pproximtion S[π/4, 3π/8] + S[3π/8, π/2].28912. There re no intervls left, nd therefore the finl pproximtion is.38145 +.32338 +.28912 =.99395 wheres the exct integrl is π/2 cos(x) = 1. Thus the error is.99395 1.6 <.5. (c) In this cse, f(x) = exp(x), =, b = 1. S[, 1] = (1 + e)/2 1.85914, S[,.5] = (1 + exp(.5))/4.66218, S[.5, 1] = (exp(.5) + exp(1))/4 1.9175. S[, b] S[, c] S[c, b].152 < 3.5 ((b )/(b )) =.15. Thus we stop with the pproximtion S[, c] + S[c, b] 1.75393 nd n error estimte (S[, b] S[, c] S[c, b])/3.35. The ctul integrtion error is exp(x) (S[, c] + S[c, b]).36. Our estimte is quite good in this cse. 7 Exercise 5.4.4 Develop n Adptive Qudrture method for rule (5.28). Let c = ( + b)/2, h = b nd pply the qudrture on [, b], [, c], nd [c, b] (we use the sme nottion s in the book): c f(x) dx + c f(x) dx = S[, b] + 14h5 45 f (4) (c 1 ), c 1 [, b], f(x) dx = S[, c] + S[c, b] + 14(h/2)5 45 f (4) (c 2 ) + 14(h/2)5 f (4) (c 3 ), 45 c 2 [, c], c3 [c, b]. Further ssuming tht f (4) (c 1 ) f (4) (c 2 ) f (4) (c 3 ) we obtin: c f(x) dx + c f(x) dx = S[, b] + 14h5 45 f (4) (c 1 ), f(x) dx S[, c] + S[c, b] + 1 14h 5 16 45 f (4) (c 1 ). We cn now subtrct the second eqution from the first to obtin: S[, b] S[, c] S[c, b] 15 1 14h 5 16 45 f (4) (c 1 ). 5
Thus the number S[, b] S[, c] S[c, b] gives n pproximtion to 15 times the error of the qudrture S[, c] + S[c, b]. The rest is exctly the sme s for other qudrtures; one stops subdividing the intervl when S[, b] S[, c] S[c, b] < 15 T OL (b )/(b orig orig ) nd returns S[, c] + S[c, b] s the pproximtion of the integrl over the intervl [,b]. 8 Computer exercise 5.2.8 Answers: () 1.547866 (b) 1.277978 (c) 1.277978 9 Computer exercise 5.2.1 See the file uniform_refinement.py vilble on the wiki. Adpt the code to use Simpson s rule insted of Trpezoid. 6