






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Jim Lambers Math 105A Summer Session I 2003- Homework Assignment 4 Solution
1
x^2 ln x dx.
Note: R 3 , 3 corresponds to N 3 (h) from Lecture 13, with h = b − a = 0.5. Solution Let f (x) = x^2 ln x denote the integrand. We begin by using the Trapezoidal Rule, or, equivalently, the Composite Trapezoidal Rule ∫ (^) b
a
f (x) dx ≈ h 2
f (a) +
n∑− 1
j=
f (xj ) + f (b)
(^) , h = b^ −^ a n
, xj = a + jh,
with n = 1 subintervals. Since h = (b − a)/n = (1. 5 − 1)/1 = 0. 5 , we have
[f (1) + f (1.5)] = 0. 22807412331084.
Next, we apply the Composite Trapezoidal Rule with n = 2 and h = (1. 5 − 1)/2 = 0.25, which yields R 2 , 1 =
[f (1) + 2f (1.25) + f (1.5)] = 0. 20120251138753.
Now, we can use Richardson Extrapolation to obtain a more accurate approximation,
Next, we use the Composite Trapezoidal Rule with n = 4 and h = (1. 5 − 1)/4 = 0.125, and obtain
R 3 , 1 =
[f (1) + 2[f (1.125) + f (1.25) + f (1.375)] + f (1.5)] = 0. 19449447318109.
Now, we can apply Richardson Extrapolation to R 2 , 1 and R 3 , 1 to obtain
Finally, we use Richardson Extrapolation with R 2 , 2 and R 3 , 2 to obtain a new approximation
% 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.5R(n-1,1)+0.5hsumf; % 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 if abs(R(n,n)-R(n-1,n-1)) Now, we can use Richardson Extrapolation to obtain a more accurate approximation,
R 2 , 2 = R 2 , 1 +
Next, we use the Composite Trapezoidal Rule with n = 4 and h = (5 − 1)/4 = 1, and obtain
R 3 , 1 =
[f (1) + 2[f (2) + f (3) + f (4)] + f (5)] = 11. 5157.
Now, we can apply Richardson Extrapolation to R 2 , 1 and R 3 , 1 to obtain
Finally, we use Richardson Extrapolation with R 2 , 2 and R 3 , 2 to obtain a new approximation
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 sufficient data.
Rk, 2 = Rk, 1 +
Rk, 1 − Rk− 1 , 1 3 =
Rk, 1 −
Rk− 1 , 1
hk 2
f (a) + 2
n∑k − 1
j=
f (a + jhk) + f (b)
hk− 1 2
f (a) + 2
nk ∑− 1 − 1
j=
f (a + jhk− 1 ) + f (b)
hk 2
f (a) + 2
2 k∑−^1 − 1
j=
f (a + jhk) + f (b)
2 hk 2
f (a) + 2
2 k∑−^2 − 1
j=
f (a + 2jhk) + f (b)
hk 3
[f (a) + f (b)] +
2 hk 3
(^2) ∑k−^2
j=
f (a + (2j − 1)hk) +
2 k∑−^2 − 1
j=
f (a + 2jhk)
hk 3
2 k∑−^2 − 1
j=
f (a + 2jhk)
hk 3 [f (a) + f (b)] +
hk 3
(^2) ∑k−^2
j=
f (a + (2j − 1)hk) + 2
2 k∑−^2 − 1
j=
f (a + 2jhk)
hk 3
f (a) + 4
n ∑k / 2
j=
f (x 2 j− 1 ) + 2
nk ∑ / 2 − 1
j=
f (x 2 j ) + f (b)
which is precisely the formula for the Composite Simpson’s Rule with h = hk.
x^2 e−x^ dx,
and verify that
1 15
∣∣S(a, b) − S
a,
a + b 2
a + b 2 , b
∫ (^) b
a
f (x) dx − S
a,
a + b 2
a + b 2 , b
where the exact value of the integral is 0.16060279414279. Solution Using S(a, b) =
h 3 [f (a) + 4f (a + h) + f (b)],
where h = (b − a)/2, we have
[f (0) + 4f (0.5) + f (1)]
is equivalent to using the Composite Simpson’s Rule on [0, π/4] with n = 4 subintervals. We obtain
I 2 = π/ 8 6 [f (0) + 4f (π/16) + f (π/8)] + π/ 8 6 [f (π/8) + 4f (3π/16) + f (π/4)]
= π/ 16 3
[f (0) + 4f (π/16) + 2f (π/8) + 4f (3π/16) + f (π/4)] = 2. 58770145345862.
Now, we need to determine whether the approximation I 2 is sufficiently accurate. Because the error in the Composite Simpson’s Rule is O(h^4 ), where h is the width of each subinterval used in the rule, it follows that the actual error in I 2 satisfies
|I 2 − I(f )| ≈
where If (f ) is the exact value of the integral of f. We find that the relation
|I 2 − I(f )| ≈
is satisfied, we have achieved sufficient accuracy on this interval and we do not need to subdivide it further. The more accurate approximation I 2 can serve as our approximation to the integral over the original interval [0, π/4].
0
x^2 sin x dx
using Gaussian quadrature with n = 2, and compare your result to the exact value, which is 0.08875528443527. Solution On the interval [− 1 , 1], the nodes for Gaussian quadrature with n = 2 are
r 2 , 0 = 0. 5773502692 , r 2 , 1 = − 0. 5773502692 ,
and the corresponding weights are
c 2 , 0 = 1, c 2 , 1 = 1.
To use these nodes and weights, we can transform the original integral into an integral over [− 1 , 1] using the change of variable
x =
[ (^) π 4 t + π 4
π 8 (t + 1), t ∈ [− 1 , 1],
which yields (^) ∫ π/ 4
0
x^2 sin x dx =
− 1
( (^) π 8
(t + 1)
sin
( (^) π 8
(t + 1)
) (^) π 8
dt.
Evaluating this integral using Gaussian quadrature yields the approximation ∫ (^) π/ 4
0
x^2 sin x dx =
− 1
( (^) π 8 (t + 1)
sin
( (^) π 8 (t + 1)
) (^) π 8 dt
≈ c 2 , 0
( (^) π 8 (r 2 , 0 + 1)
sin
( (^) π 8 (r 2 , 0 + 1)
) (^) π 8
c 2 , 1
( (^) π 8 (r 2 , 1 + 1)
sin
( (^) π 8 (r 2 , 1 + 1)
) (^) π 8 ≈ (1)
( (^) π 8
sin
( (^) π 8
) (^) π 8
( (^) π 8
sin
( (^) π 8
) (^) π 8 ≈ 0. 08926301565865 ,
which has an absolute error of 5. 077 × 10 −^4. An equivalent approach is to apply the above change of variable to the nodes r 2 , 0 and r 2 , 1 to obtain the Gaussian quadrature nodes for [0, π/8],
˜r 2 , 0 = 0. 61942400222800 , ˜r 2 , 1 = 0. 16597416116945 ,
and scale the weights by (π/4)/2 to obtain the new weights
˜c 2 , 0 = ˜c 2 , 1 = π/ 8 ,
and then compute ∫ (^) π/ 4
0
x^2 sin x dx ≈ ˜c 2 , 0
˜r^22 , 0 sin ˜r 2 , 0
r˜ 22 , 1 sin ˜r 2 , 1
Solution On the interval [− 1 , 1], the nodes for Gaussian quadrature with n = 4 are
r 4 , 0 = 0. 8611363116 , r 4 , 1 = 0. 3399810436 , r 4 , 2 = − 0. 3399810436 , r 4 , 3 = − 0. 8611363116 ,
and scale the weights by (π/4)/2 to obtain the new weights
˜c 4 , 0 = ˜c 4 , 3 = 0. 13660227823522 , ˜c 4 , 1 = ˜c 4 , 2 = 0. 25609680346350 ,
and then compute ∫ (^) π/ 4
0
x^2 sin x dx ≈
i=
˜c 4 ,i
˜r 42 ,i sin ˜r 4 ,i
R
e−(x+y)^ dA
where R is the region in the plane bounded by the curves y = x^2 and y =
x. Implement the algorithm using MATLAB. Solution The following MATLAB function implements Algorithm 4.4.
% this function computes the integral of f(x,y) on the % domain a <= x <= b, and c(x) <= y <= d(x), where f is % assumed to be an inline function of x and y, and % c and d are assumed to be inline functions of x. % The Composite Simpson’s Rule with n subintervals in the % x direction and m subintervals in the y direction. function J=hw4prob489(f,a,b,c,d,m,n) h=(b-a)/n; J1=0; J2=0; J3=0; for i=0:n, x=a+ih; HX=(d(x)-c(x))/m; K1=f(x,c(x))+f(x,d(x)); K2=0; K3=0; for j=1:m-1, y=c(x)+jHX; Q=f(x,y); if rem(j,2)==0,
else K3=K3+Q; end end % L is the approximate integral of f(xi,y) from % c(xi) to d(xi), where xi=a+ih L=(K1+2K2+4K3)HX/3; if i==0 | i==n, J1=J1+L; elseif rem(i,2)==0, J2=J2+L; else J3=J3+L; end end J=h(J1+2J2+4J3)/3;
Using this function, we obtain the approximation 0.14791026834524.
1
x^2 + 9
dx
with n = 4. Solution Using the transformation t = x−^1 , we obtain ∫ (^) ∞
1
x^2 + 9
dx = −
1
t^2
t−^2 + 9
dt =
0
1 + 9t^2
dt.
The following MATLAB function implements the Composite Simpson’s Rule ∫ (^) b
a
f (x) dx ≈ h 3
f (a) + 2
(n/ ∑2)− 1
j=
f (x 2 j ) + 4
∑^ n/^2
j=
f (x 2 j− 1 ) + f (b)
where h = (b − a)/n and xj = a + jh for j = 0, 1 ,... , n.