p MA/CS 371 - Lab 4

MA/CS 371 - Lab 4
Numerical Integration - Upper and Lower Sums and the Trapezoid Rule


Section 1: Introduction

The goal of this lab is to introduce you to:

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

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

Section 2: Topics for Lecture

This time I'm going to briefly lecture about some of the formatting options available with MATLAB's fprintf command. This command behaves pretty much the same in MATLAB as it does in C. I'll show you the overall idea and explain a few of the simpler types.

Section 3: Upper and Lower Sums

The file sums.m is a bare skeleton which you will fill out into a program which computes approximations to a particular integral via the upper and lower sums method.

The function we will be approximating will be

                pi/2
	   	/             
                |   1 - sin(x)  dx
		/
		0
The vector q in the program indicates the number of subintervals to use for each approximation. The MATLAB statement
	for i=q,
runs through the loop length(q) times, setting i to q(1) the first time, q(2) the second time, etc.

Complete the program sums.m and answer the first two questions.

Section 4: The Trapezoid Rule

The file trap.m is a bare skeleton which you will fill out into a program which approximates the above function by the trapezoid rule. Complete the program trap.m and answer the next two questions.

Section 5: Submitting Your Work

When your programs sums.m and trap.m are ready, run
		~cs371/submit lab4
I will accept solutions through 11:59pm Thursday.

As before, I would prefer that you e-mail me the answers to the problems but there will be a few hard copies in lab.

This Week's Questions