Lab 2

Quadrature Rules - Finding Pi

The goal is to implement and compare the basic Quadrature Rules for

the integral of a given function F(x) over an interval [a,b], using M subintervals.

1. Implement the

a. Inputs to the function RectRule should be

b. The code should print out:

and value of

nicely formated, like: RectRule for M= VALUE : RL= VALUE , RR= VALUE

c. Debug on

d. Debug on

e. Test it on

Looks like rather large M is needed to get a decent approximation...

2. Implement the

Repeat a - e above to debug and test the Midpoint Rule.

3. Implement the

Repeat a - e above to debug and test the Trapezoidal Rule.

4. Create a Matlab function

A. calls each of your quadrature rules (with the same a, b, M),

B. computes the

C. prints a (nicely formatted) table like:

Comparison of Quadrature Rules using M= VALUE subintervals:

Rule Value Error

5.

Very easily, from the

In fact, this is the best way to set the value of

6. Use your

a. Using M = 1000, how many correct digits does TrapzRule produce ?

b. Using M = 100000, how many correct digits does TrapzRule produce ?

c. What is the connection between the formulas for

7.

0. % NAME , Date , Lab2

1. Answers to questions 6a, 6b, 6c (as comments)

If your results are unexpected, any guesses as to what may be happening ?

% =============================================== (separator)

2. your "FCN.m" file, showing coding of the integrand for PI in 6.

% =============================================== (separator)

3. your "Quadr.m" file

% =============================================== (separator)

4. your "TrapzRule.m" file

% =============================================== (separator)

copy-paste the output at the end of Lab2.m as comment lines.

Then publish again to produce PDF.