Anda di halaman 1dari 11

Jim Lambers MAT 460/560 Fall Semester 2009-10 Homework Assignment 13 Solution

Section 4.4
1. Write a MATLAB function that accepts as input a MATLAB function f(x), two real numbers a and b, and a positive integer n, and then uses the Composite Trapezoidal rule with the given value of n to compute the integral of f(x) from a to b. Use your function with the indicated values of to approximate the following integrals. 2 (a) 1 ln , = 4 2 (b) 2 3 , = 4 2 (c) 0 22 , = 6 +4 2 (d) 0 cos , = 6 2 (e) 0 2 sin 3 , = 8 3 (f) 1 2 , = 8 +4 5 1 (g) 3 2 4 , = 8 3/8 (h) 0 tan , = 8 Note: Your function must use MATLABs feval function to evaluate the integrand at a given point. To learn how to use feval, you may either read the help page by typing help feval in MATLAB, or consult the M-le fevalsamples.m that is posted on the Code page of the site. Solution The following MATLAB function approximates the integral of a given function f from a to b using the Composite Trapezoidal Rule with n subintervals. function t=hw3prob441(f,a,b,n) h=(b-a)/n; y=0; xj=a; for j=1:n-1, xj=xj+h; y=y+feval(f,xj); end t=(h/2)*(feval(f,a)+2*y+feval(f,b)); 1

In the following MATLAB session, we use this function to compute the required integrals. >> f=inline(x*log(x)); >> y=hw3prob441(f,1,2,4) y = 0.63990047768799 >> f=inline(x3*exp(x)); >> y=hw3prob441(f,-2,2,4) y = 31.36528565006375 >> f=inline(2/(x2+4)); >> y=hw3prob441(f,0,2,6) y = 0.78424076661782 >> f=inline(x2*cos(x)); >> y=hw3prob441(f,0,pi,6) y = -6.42872221802316 >> f=inline(exp(2*x)*sin(3*x)); >> y=hw3prob441(f,0,2,8) y = -13.57597939179939 >> f=inline(x/(x2+4)); >> y=hw3prob441(f,1,3,8)

y = 0.47697686651472 >> f=inline(1/sqrt(x2-4)); >> y=hw3prob441(f,3,5,8) y = 0.60549751454215 >> % in this case, no inline function is needed, >> % we can just pass the name of the function >> y=hw3prob441(tan,0,3*pi/8,8) y = 0.97092630667913 11. Determine the values of and required to approximate 2 2 sin 3
0

to within 104 . (a) Use the Composite Trapezoidal rule. Solution The error term is 2 (), [, ]. 12

We have = 0, = 2, = (2 0)/, and () = 52 sin 3 + 122 cos 3. It follows that the error term has the form 1 2 [52 sin 3 + 122 cos 3], 6 [0, 2].

To determine the maximum value of () on [0, 2], we examine () = 462 sin 3 + 92 cos 3.

Factoring out 2 , we nd that () has a critical number at (1/3) tan1 (9/46) = 0.06440382793. This yields (0.06440382793) = 12.30363348. However, (2) = 705.3601028, so that is the maximum value on [0, 2]. Therefore, 2 (705.3601028)2 117.56001712 . ( ) 12 6

It follows that in order to ensure that the error is bounded by 104 , we must have < 0.0009222956913. Since = 2/, this implies that we must have > 2168. (b) Use the Composite Simpsons rule. Solution The error term is 4 (4) (), [, ]. 180

We have = 0, = 2, = (2 0)/, and (4) () = 1192 sin 3 1202 cos 3. It follows that the error term has the form 1 4 [1192 sin 3 1202 cos 3], 90 [0, 2].

To determine the maximum value of (4) () on [0, 2], we examine (5) () = 1222 sin 3 5972 cos 3. Factoring out 2 , we nd that (4) () has a critical number at (1/3) tan1 (597/122) = 0.4564055636. This yields (4) (0.06440382793) = 350.3201505. However, (4) (2) = 4475.409818, so that is the maximum value on [0, 2]. Therefore, 4 (4) (4475.409818)4 () 49.726775764 . 180 90

It follows that in order to ensure that the error is bounded by 104 , we must have < 0.03765758151. Since = 2/, this implies that we must have 54. (c) Use the Composite Midpoint rule. Solution The error term is 2 (), [, ]. 6 We have = 0, = 2, = (2 0)/( + 2), and () = 52 sin 3 + 122 cos 3. It follows that the error term has the form 1 2 [52 sin 3 + 122 cos 3], 3 4 [0, 2].

From part (a), the maximum value of () on [0, 2] is 705.3601028. Therefore, 2 (705.3601028)2 ( ) 235.120034272 . 6 3 It follows that in order to ensure that the error is bounded by 104 , we must have < 0.0006521615374402917. Since = 2/( + 2), and must be even, this implies that we must have 3066.

Section 4.5
1. Use Romberg integration to compute 3,3 for the integral
1 1.5

2 ln .

Note: 3,3 corresponds to 3 () from Lecture 13, with = = 0.5. Solution Let () = 2 ln denote the integrand. We begin by using the Trapezoidal Rule, or, equivalently, the Composite Trapezoidal Rule 1 () () + , = + , ( ) + () , = 2
=1

with = 1 subintervals. Since = ( )/ = (1.5 1)/1 = 0.5, we have 1,1 = 0.5 [ (1) + (1.5)] = 0.22807412331084. 2

Next, we apply the Composite Trapezoidal Rule with = 2 and = (1.5 1)/2 = 0.25, which yields 0.25 2,1 = [ (1) + 2 (1.25) + (1.5)] = 0.20120251138753. 2 Now, we can use Richardson Extrapolation to obtain a more accurate approximation, 2,2 = 2,1 + 2,1 1,1 = 0.19224530741310. 3

Next, we use the Composite Trapezoidal Rule with = 4 and = (1.5 1)/4 = 0.125, and obtain 3,1 = 0.125 [ (1) + 2[ (1.125) + (1.25) + (1.375)] + (1.5)] = 0.19449447318109. 2 5

Now, we can apply Richardson Extrapolation to 2,1 and 3,1 to obtain 3,2 = 3,1 + 3,1 2,1 = 0.19225846044561. 3

Finally, we use Richardson Extrapolation with 2,2 and 3,2 to obtain a new approximation 3,3 = 3,2 + 3,2 2,2 = 0.19225933731444. 24 1

5. Use Romberg integration to approximate the integral in Exercise 1 to within 106 . Compute the Romberg table until either 1,1 , < 106 , or = 10. Compare your result to the exact value of the integral, which is 0.192259357732796. Solution The following MATLAB function carries out Romberg integration to approximate the integral of a function f from a to b until 1,1 , < tol or = 10. % this function uses romberg integration to approximate % the integral of f from a to b, until consecutive % approximations agree to within tol function R=hw4prob453(f,a,b,tol) h=b-a; % compute initial approximation using Trapezoidal Rule R(1,1)=(h/2)*(feval(f,a)+feval(f,b)); % build triangular array of approximations, with up to % ten rows for n=2:10, % use Composite Trapezoidal Rule sumf=0; xj=a+h/2; for j=1:2(n-2), sumf=sumf+feval(f,xj); xj=xj+h; end R(n,1)=0.5*R(n-1,1)+0.5*h*sumf; % repeated Richardson Extrapolation to improve the % order of accuracy to O(h(2n)) for j=2:n, R(n,j)=R(n,j-1)+(R(n,j-1)-R(n-1,j-1))/(4(j-1)-1); end % if consecutive approximations along the diagonal % are sufficiently close, quit 6

if abs(R(n,n)-R(n-1,n-1))<tol, break; end % halve step size to set up next iteration h=h/2; end In the following MATLAB session, we use this function to approximate the integral in Exercise 1 to within 106 . >> f=inline(x2*log(x)); >> R=hw4prob453(f,1,1.5,1e-6) R = 0.22807412331084 0.20120251138753 0.19449447318109 0.19281809429207 0 0.19224530741310 0.19225846044561 0.19225930132906 0 0 0.19225933731444 0.19225935738796 0 0 0 0.19225935770658

The matrix R contains the approximations , generated by Romberg integration. Our nal approximation is 4,4 = 0.19225935770658. The absolute error in this approximation is 2.62 1011 . 5 7. Use the following data to approximate 1 () as accurately as possible. () 1 2.4142 2 2.6734 3 2.8974 4 3.0976 5 3.2804

Solution We begin by using the Trapezoidal Rule, or, equivalently, the Composite Trapezoidal Rule 1 () () + ( ) + () , = , = + , 2
=1

with = 1 subintervals. Since = ( )/ = (5 1)/1 = 4, we have 4 1,1 = [ (1) + (5)] = 11.3892. 2 Next, we apply the Composite Trapezoidal Rule with = 2 and = (5 1)/2 = 2, which yields 2 2,1 = [ (1) + 2 (3) + (5)] = 11.4894. 2 7

Now, we can use Richardson Extrapolation to obtain a more accurate approximation, 2,2 = 2,1 + 2,1 1,1 = 11.5228. 3

Next, we use the Composite Trapezoidal Rule with = 4 and = (5 1)/4 = 1, and obtain 3,1 = 0.125 [ (1) + 2[ (2) + (3) + (4)] + (5)] = 11.5157. 2

Now, we can apply Richardson Extrapolation to 2,1 and 3,1 to obtain 3,2 = 3,1 + 3,1 2,1 = 11.52446. 3

Finally, we use Richardson Extrapolation with 2,2 and 3,2 to obtain a new approximation 3,3 = 3,2 + 3,2 2,2 = 11.52457. 24 1

This is a sixth-order-accurate approximation, and it is the most accurate approximation we can obtain, since to proceed any further using Richardson Extrapolation, we would need to use the Composite Trapezoidal Rule with 9 quadrature nodes, for which we do not have sucient data. 13. Show that the approximation ,2 is the same as that given by the Composite Simpsons rule described in Theorem 4.4 with = . Solution For each = 1, 2, . . . , the approximation ,1 computed using the Composite Trapezoidal Rule uses + 1 quadrature nodes 0 , 1 , . . . , , where = 21 and = + for = 0, 1, . . . , . Therefore, we have ,2 = ,1 + = = ,1 1,1 3 4 1 ,1 1,1 3 3 1 4 () + 2 ( + ) + () 3 2 =1 1 1 1 1 () + 2 ( + 1 ) + () 3 2 =1 1 1 2 4 () + 2 ( + ) + () 3 2
=1

2 1 2 1 2 () + 2 ( + 2 ) + () 3 2
=1

[ () + ()] + 3 2 2 1 2 2 2 2 ( + (2 1) ) + ( + 2 ) 3 =1 =1 2 2 1 2 ( + 2 ) 3 =1 2 2 1 2 2 [ () + ()] + 4 ( + (2 1) ) + 2 ( + 2 ) 3 3 =1 =1 /2 /21 () + 4 (2 1 ) + 2 (2 ) + () 3


=1 =1

which is precisely the formula for the Composite Simpsons Rule with = .

Section 4.6
1. Compute the Simpsons rule approximations to (, ), (, ( + )/2), and (( + )/2, ) for the integral 1 2 ,
0

and verify that ) ( ) ) ( ) ( ( 1 + + + + , , , (, ) , () , 15 2 2 2 2 where the exact value of the integral is 0.16060279414279. Solution Using (, ) = where = ( )/2, we have (, ) = (0, 1) 1 = [ (0) + 4 (0.5) + (1)] 6 9 [ () + 4 ( + ) + ()], 3

= 0.16240168348068, ( , + 2 ) = (0, 1/2) 1 [ (0) + 4 (0.25) + (0.5)] 12 = 0.02886107172467, = ( ) + , = (1/2, 1) 2 1 = [ (0.5) + 4 (0.75) + (1)] 12 = 0.13186140414724.

It follows that ) ( ( ) 1 + + (, ) , , 15 2 2 = 1 0.16240168348068 15 0.02886107172467 0.13186140414724

= 0.0001119471739181033, and

) ( ) ( + + , () , 2 2

= 0.16060279414279 0.02886107172467 0.13186140414724 = 0.0001196817291177488,

so the error estimate and the actual error agree to two signicant digits. 3. Use Adaptive quadrature to approximate the integral /4 3 sin 2
0

to within 103 . You may not use MATLAB. Solution Let () = 3 sin 2 denote the integrand. First, we use Simpsons Rule, or, equivalently, the Composite Simpsons Rule with = 2 subintervals, to obtain an approximation 1 to this integral. We have 1 = /4 [ (0) + 4 (/8) + (/4)] = 2.58369640324748. 6

Then, we divide the interval [0, /4] into two subintervals of equal width, [0, /8] and [/8, /4], and integrate over each one using Simpsons Rule to obtain a second approximation 2 . This 10

is equivalent to using the Composite Simpsons Rule on [0, /4] with = 4 subintervals. We obtain 2 = /8 /8 [ (0) + 4 (/16) + (/8)] + [ (/8) + 4 (3/16) + (/4)] 6 6 /16 = [ (0) + 4 (/16) + 2 (/8) + 4 (3/16) + (/4)] 3 = 2.58770145345862.

Now, we need to determine whether the approximation 2 is suciently accurate. Because the error in the Composite Simpsons Rule is (4 ), where is the width of each subinterval used in the rule, it follows that the actual error in 2 satises 2 ( ) 1 2 1 , 15

where ( ) is the exact value of the integral of . We nd that the relation 2 ( ) 1 2 1 = 2.67 104 < 103 15

is satised, we have achieved sucient accuracy on this interval and we do not need to subdivide it further. The more accurate approximation 2 can serve as our approximation to the integral over the original interval [0, /4].

11

Anda mungkin juga menyukai