MA/CS 371 - Lab 5
More Numerical Integration - The Composite Trapezoid Rule (CTR) Versus The Composite Simpson's Rule (CSR)


Section 1: Introduction

In this lab you will:

If you have not already done so, create a directory for this lab and copy the lab 5 files into it. If you start off in your home directory you can do the following:

	mkdir ~/cs371/lab5
	cd ~/cs371/lab5
	cp ~cs371/lab5/* .
and (as always) don't forget to type that last period.

Section 2: Topics for Lecture

Today in lecture I'm going to discuss the flops command which is used to count the number of "floating-point operations" that MATLAB performs. Comparing the "flops count" of two different algorithms is one way of determining which is more efficient.

Section 3: Today's Function

Today's special guest function is one with some flat spots and some sharp curves:
		    x	   sin(x)
	f(x) = sin(e )  - e      
This week we are going to estimate the integral of f(x) from -10 to 3 with the Composite Simpson's Rule and compare the results to the Composite Trapezoid Rule.

First off, I recommend that you plot f(x) on the interval [-10,3] just to see what it's doing. Make sure to use enough points that you can see how the function wiggles around towards the upper end of the interval.

Section 4: Implementing the Composite Trapezoid Rule

The trap.m file given to you for this lab is the one that I wrote for the previous lab assignment. For this lab, you should modify trap.m in the following ways:

Section 5: Implementing the Composite Simpson's Rule

Using your trap.m function as a template, make a new file simpson.m which will approximate the integral with the CSR. (Note: Problem 5.4.1 in the book contains the formula for the CSR.) Use the same number of intervals as in trap.m and format your output the same way.

Recall that the CSR requires an even number of intervals (or an odd number of evaluation points.) You will need to change the vector q in simpson.m to accommodate this.

Section 6: Submitting Your Work

When you are ready, run
	~cs371/submit lab5
to submit your simpson.m and trap.m files.

This Week's Questions