Wichita State University Logo

M451: Mathematical Computing with MATLAB©

Assignment 10: Numerical Integration



Instructions:

Submit your work in the form of a multiple .m files. Please put your first initial and last initial (in lowercase letters) before each script or function name. If you are submitting a script file, start your file off with the command clear and please clearly label and describe each problem with comments in your file.

Question 1:The Midpoint Rule

Write a function called MidptApprox that approximates the integral $\int_{a}^{b}f(x)\; dx$ using the Midpoint Rule defined as follows:


$$ \int_{a}^{b}f(x)\; dx \approx M_{n} = \sum_{i=1}^{n}f\left(\overline{x}_{i}\right)\Delta x\quad\quad\text{where}\quad\quad \Delta x = \dfrac{b-a}{n} \quad\text{and}\quad \overline{x}_{i} = \dfrac{x_{i-1} + x_{i}}{2}. $$


Include in your function file at least two ways of determining the value of $M_{n}$ and have the function run through the calculations of both and display which method it is using and the solution (even though the answers will be identical).



Question 2: The Trapezoidal Rule

Write a function called TrapApprox that approximates the integral $\int_{a}^{b}f(x)\; dx$ using the Trapezoidal Rule defined as follows:


$$ \int_{a}^{b}f(x)\; dx \approx T_{n} = \dfrac{\Delta x}{2}\Big(f\left(x_{0}\right) + 2f\left(x_{1}\right) + 2f\left(x_{2}\right) + \cdots + 2f\left(x_{n-1}\right) + f\left(x_{n}\right)\Big) \quad\quad\text{where}\quad\quad \Delta x = \dfrac{b-a}{n} \quad\text{and}\quad x_{i} = a + i\Delta x . $$


Include in your function file at least two ways of determining the value of $T_{n}$ and have the function run through the calculations of both and display which method it is using and the solution (even though the answers will be identical).



Question 3: Simpson's Rule

Write a function called SimpApprox that approximates the integral $\int_{a}^{b}f(x)\; dx$ using Simpson's Rule defined as follows:


$$ \int_{a}^{b}f(x)\; dx \approx S_{n} = \dfrac{\Delta x}{3}\Big(f\left(x_{0}\right) + 4f\left(x_{1}\right) + 2f\left(x_{2}\right) + 4f\left(x_{3}\right) + \cdots + 2f\left(x_{n-2}\right) + 4f\left(x_{n-1}\right) + f\left(x_{n}\right)\Big)\\[15pt] \quad\quad\text{where}\quad\quad \Delta x = \dfrac{b-a}{n} \quad\text{and}\quad x_{i} = a + i\Delta x \quad\text{with }n\text{ being even}. $$


Include in your function file, at least two ways of determining the value of $S_{n}$ and have the function run through the calculations of both and display which method it is using and the solution (even though the answers will be identical).