# Assignment 7

This assignment has several parts.

1. Write a Matlab function called simpson that takes four arguments. The first argument is a function whose integral is to be approximated using a composite Simpson's rule. The second and third arguments are the left and right endpoints of the interval of integration. The last argument is the number of subintervals over which the Simpson's rule will be applied. The output of the function is the value of the approximation to the integral. Note that the function must test the number of subintervals input, and if that number is odd or nonpositive, it must stop the function with an error message. Recall that Simpson's rule approximates an integral over $\left(a,b\right)$ using the formula
where $n$ is the number of subintervals used and $h=\left(b-a\right)/n$, with ${x}_{i}=a+ih$.
2. Run this function and the trapezoidal rule function for $n\in \left\{10,100,1000,\dots ,1e6\right\}.$ Use the two functions quartic and unitstep you wrote in assignment 6 as the examples to run these on, integrating from -1 to 1. Record the errors, that is, the absolute value of the difference between the approximations the functions give and the actual analytical integrals.
3. Use log-log axes to plot the errors of both methods against $h$ in a single figure. Put $h$ on the horizontal axis, and make one curve for errors in the trapezoidal rule, and another on the same axes for the errors in Simpson's rule. There will be two figures: one for the quartic, and one for the unit step function. Save them both as JPEG images. Needless to say, you will label the axes.
4. Write a brief paper about the calculations. The first section will contain a brief discussion of Simpson's rule. Be sure to include a theoretical bound for the error in the approximation. The second section will discuss the results you found in part 2. Compare the rates at which the errors decrease for the trapezoidal rule and Simpson's rule. Compare and contrast the rates of decrease in the error for the quartic with the rate of decrease for the unit step function. There should be an appendix in which a listing of your Simpson's rule function appears (using a verbatim environment). Obviously you will include the two figures you created.

You will email the LaTeX file and your two figures to the instructor to turn the assignment in. The assignment is worth 70 points and is due in the instructor's email inbox by 9 AM on Thursday, 8 November.

Welcome to Math 300 for summer, 2013.

Department of Mathematics, PO Box 643113, Neill Hall 103, Washington State University, Pullman WA 99164-3113, 509-335-3926, Contact Us