Assignment 7
This assignment has several parts.
- 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
using the formula
where is the number of subintervals used and , with . - Run this function and the trapezoidal rule function for 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.
- Use log-log axes to plot the errors of both methods against in a single figure. Put 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.
- 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.