## 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

- b

I(f) = f(x)dx: (1)

a

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) | ||||||

Input:

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: | |||

n | 1 | ||||||||

to compute the numerical approximation of the integral (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 | cos | 3 | 2 | x^{3} |
dx: | |||||

I = ^{Z} _{3} |
_{e} x |
(2) | |||||||||

1 + x^{2} |
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 I_{n}j |
n = 2; 3; :::; 10000 | (3) |

where I = 1:6851344770476 is the reference value for the integral (2), while I_{n} 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.