Description
Please submit to CANVAS a .zip le that includes the following Matlab functions:
int midpoint rule.m
int trapezoidal rule.m
int Simpson rule.m
test integration.m
Exercise 1 Consider the following integral of a function f(x) on a nite interval [a; b]

_{b}
I(f) = f(x)dx: (1)
a
Write three Matlab/Octave functions implementing, respectively, the composite midpoint rule, the composite trapezoidal rule, and the composite Simpson rule to compute the numerical approximation of I(f). Such functions should be of the form

function [I]=int
midpoint
rule(fun,a,b,n)
(composite midpoint rule)
function
[I]=int
trapezoidal
rule(fun,a,b,n)
(composite trapezoidal rule)
function
[I]=int
Simpson
rule(fun,a,b,n)
(composite Simpson rule)
Input:
fun: function handle representing f(x)
a,b: endpoints of the integration interval
n: number of evenlyspaced points in [a; b] (including endpoints)

x_{j} = a + (j 1)h;
h =
b
a
;
j = 1; :::n:
n
1
Output:
I: numerical approximation of the integral (1).
Exercise 2 Use the functions you coded in Exercise 1 to compute the numerical approximation of the integral

1
1
3
2
_{x}3
I = ^{Z}
cos
e
x
dx:
(2)
3
1 + x^{2}
2
30
To this end, write a Matlab/Octave function
1
[em,et,es] = function test integration()
that returns the following items:
en, et, es: row vectors with components the absolute values of the integration errors
jI_{ref} I_{n}j n = 2; 3; :::; 10000 (3)
obtained with the midpont (vector en), trapezoidal (vector et) and Simpson (vector es) rules. Here,
I_{ref} = 1:6851344770476
is the reference value of the integral (2) while I_{n} is the numerical approximation obtained by using the composite midpoint, trapezoidal, and Simpson rules with n nodes.
The function test integration() should also return the plot of the integrand function appearing in (2) in figure(1), and the plots of the errors en, et and es versus n in a loglog scale in figure(2) (one gure with three plots). (Hint: use the Matlab command loglog()).
2