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
Exercise 1 Consider the following integral
I(f) = f(x)dx: (1)
Write three Matlab functions implementing, respectively, the composite midpoint rule, the com-posite trapezoidal rule, and the composite Simpson rule to compute the numerical approximation of I(f). Such functions should be in 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)|
fun: function handle representing f(x)
a,b: endpoints of the integration interval
n: number of evenly-spaced points in [a; b] (including endpoints)
|x||j||= a + (j||1)h;||h =||b a||;j = 1; :::n:|
to compute the numerical approximation of the integral (1).
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
|I = Z 3||e x||(2)|
|1 + x2||2||30|
To this end, write a Matlab script test integration.m that returns the following items:
|1.||A plot of the integrand function in (2) (in figure(1));|
|2.||A plot of the error|
|e(n) = jI Inj||n = 2; 3; :::; 10000||(3)|
where I = 1:6851344770476 is the reference value for the integral (2), while In is the numerical approximation obtained by using the integration rules you coded in Exercise 1. In particular, plot in the same figure(2) the error (3) versus n (use the Matlab command loglog()) the composite midpoint rule, the composite trapezoidal rule, and the composite Simpson rule.