# MACM 316 – Computing Assignment 7

Original price was: \$35.00.Current price is: \$30.00.

Rate this product

MACM 316 – Computing Assignment 7
Computing Assignment – Trapezoidal rule
Consider a partition x0, . . . , xN of an interval [a, b]. For an integrable function f defined in the
interval [a, b], the trapezoidal rule for the integral of f is
Z b
a
f(x)dx ≈
1
2
X
N
k=1

f(xk−1) + f(xk)

(xk − xk−1).
In general, the distance between consecutive points in the partition of [a, b] does not have to be the
same. When, this partition consists of equally-spaced points, we have the formula
Z b
a
f(x)dx ≈
h
2
X
N
k=1

f(xk−1) + f(xk)

, h := xk − xk−1, ∀ k.
The goal of this assignment is to investigate the rate of convergence of this rule depending on the
functions we want to integrate. To do this, first download from Canvas the MATLAB function
that implements the trapezoidal rule. It has the following inputs: lower and upper bounds of the
interval, number of points in the partition, and the function you want to integrate. To test the
function, compute the integral of the function f(x) := x
3 over [0, 1] with N = 100 points. What is
the value you get?
Consider the intervals I1 := [0,
π
3
] and I2 := [0, 2π]. Approximate the integrals over both I1 and I2
of the functions f1(x) := sin( 1
2
x), f2(x) := |sin(2x)|, and f3(x) := cos(x) by using the Trapezoidal
rule. Then plot the absolute error of the computed integral and its corresponding true value. Note
that the true values can be easily computed by hand. Also, find the rate of convergence at which
each error is going to zero. Which one is the fastest? Note that one error plot is always close to
machine epsilon, what do you think is causing this extreme accuracy? This last question is difficult
– you should use an internet search to try and get some information on what is happening and
perhaps why.
Your conclusions should be explained in a one-page report. Your report must include the following:
(a) Output (value of the integral) of your test case f(x) = x
3 on [0, 1] with N = 100 points.
(b) Two loglog plots of the absolute errors, one for I1 and one for I2.
(c) Rate of convergence of each error (6 in total). Why is one of the plots around machine epsilon
for almost any values of N?
(d) Make sure you answer all the questions in the document.
2

Scroll to Top