Starting from:

$30

MATH 340 LAB 9 Assignment

MATH 340
LAB 9 Assignment

Numerical Integration:
Trapezoid Rule
To approximate I(f) = R b
a
f(x)dx , let the number of subintervals to be n and let
h =
b − a
n
to be the length of each subinterval. The endpoints (equispaced) of the subintervals
are given by
xj = a + hj, j = 0 , . . . , n
Then the approimation of I(f) by the Trapezoid rule is given by the formula
Tn(f) = h

1
2
f(x0) + f(x1) + f(x2) + . . . + f(xn−2) + f(xn−1) + 1
2
f(xn)

(1)
Simpson’s Rule
For the same number of subintervals and grid points the Simpson’s rule follows:
Sn(x) = h
3
[f(x0) + 4f(x1) + 2f(x2) + 4f(x3) + 2f(x4) + . . . + 2f(xn−2) + 4f(xn−1) + f(xn)]
(2)
Problem 1:
Use both methods above to find the approximations In(f) of integrals I(f) = R b
a
f(x)dx,
1
with n = 21
, 2
2
, 2
3
, . . . , 2
9
, for the functions:
(a)
Z π
0
e
x
cos(4x)dx =
e
π − 1
17
(b)
Z 1
0
x
5/2
dx =
2
7
(c)
Z 5
0
1
1 + (x − π)
2
dx = arctan(5 − π) + arctan(π)
(d)
Z π
−π
e
cos x
dx = 7.95492652101284
(e)
Z π/4
0
(e
cos x
)dx = 1.93973485062365
(f)
Z 1
0

xdx =
2
3
For each of the approximated integrals In(f) calculate the error as the difference
from the exact value of the integral I(f), given by
Errn = |I(f) − In(f)|
For each exercise (a)-(f) make one table. In each table, each row should have the
number n of points used, the approximation of the integral by Trapezoidal Rule,
its error Errn, and its ratio Ration =
Errn−1
Errn
, respectively, then the approximation
by Simpson’s Rule, its error and its ratio, respectively.
This format can be printed this way:
fprintf(’n Tr Rule Err_n Trap Ratio_n Trap Simpon Err_n Simps Ratio_n Simps\nComment on your results. For each execution (a)−(f), which method is better?
And why?
Boole’s Rule
The degree four Newton-Cotes rule, often called Boole’s rule, approximates I(f) =
R x4
x0
f(x)dx as follows:
Bn(x) = 2h
45
[7f(x0) + 32f(x1) + 12f(x2) + 32f(x3) + 7f(x4)] (3)
2
Problem 2:
Use your code to find the degree of precision of Trapezoidal Rule, Simpson’s Rule
and Boole’s Rule. To recall how you find the degree of precision of an integration
formula, please refer to definition 5.2 on page 258 and example 5.7 on page 259 of
your textbook (you should test your rule with monomials 1, x, x2
, x3
, . . .).
3

More products