Department of Computer Science and Engineering CSE 130
University of California at San Diego Fall 1999

Team Project 1

DUE FRIDAY OCTOBER 22, 1999, BEFORE 6 PM.


What did we mean when we wrote that main will contain the drivers for your program?

The purpose of this project is to make you aware of some important differences and similarities between the C and Pascal languages. In your team report, you should discuss the ways in which Pascal can be considered more high-level, while C is more flexible.

The assignment is to implement programs with similar behavior in both languages. In each language you should write two routines for doing numerical integration using so-called Riemann sums, named lriemann and rriemann. The signature of each routine should be the same:

        (real -> real) x real x real x integer -> real.

The first argument is the function to be integrated, the second and third arguments are lower and upper bounds, and the fourth argument specifies into how many subintervals to divide the interval between the lower and upper bounds for Riemann's rule.

The formula that defines the algorithm for Riemann's rule is simple. Let f be the function that we wish to integrate over the closed interval [a,b] where a < b.  Let n be the number of intervals we wish to use, so the length of each interval is (b-a)/n.  Let this value be called delta.

Riemann's left-hand approximation to the integral, computed by lriemann, is

        f(a)*delta + f(a+delta)*delta + f(a+2*delta)*delta + ... + f(b-delta)*delta.

Riemann's right-hand approximation to the integral, computed by rriemann, is

       f(a+delta)*delta + f(a+2*delta)*delta + ... + f(b)*delta.

In addition to the lriemann and rriemann functions, you will implement four other functions, all with the signature real -> real. You should implement tangent, square, reciprocal (1/x), and twotothepower (2^x). For example, tangent might be as follows in Pascal:

        function tangent (x: real): real;
        begin
                tangent :=  sin(x) / cos(x);
        end;
 

WHAT TO SUBMIT BY COMPUTER

You should create six files: riemann.p, funcs.p, main.p, riemann.c, funcs.c, and main.c.  In each language, riemann is to contain the two Riemann functions described above, funcs is to contain the four math functions described in this document, and main will contain the drivers for the program.

To turn in your work, you will use a script called bundle. Simply cd to the directory containing all four source files and type the Unix command bundle P1. The bundle script knows which files to look for and submit. Remember to check the broadcast message when you log in to your CSE 130 account for any changes to these directions.
 

WHAT TO SUBMIT ON PAPER

You should describe all your work in a well-written report of length at most ten pages.  The report should have a table of contents and a list of references, with references cited as appropriate in the text of the report. References include web pages and books. One recommended book is Calculus by Deborah Hughes-Hallett, Andrew M. Gleason, et al. The contents of the report will be discussed in more detail in class.

As mentioned above, the report should discuss the ways in which Pascal is "higher-level" while C is more flexible, as illustrated by this programming project.  Issues to consider include:

You should also use your programs to do an experimental study of the accuracy of Riemann sums as a method of numerical integration.  For a monotonic function (a function which is either increasing over the whole interval [a,b] or decreasing) the true value of the integral is guaranteed to be bracketed between the left-hand and right-hand Riemann sums.  The error in computing the true integral of f using n intervals is therefore less than

        epsilon   =   | lriemann(f,a,b,n) - rriemann(f,a,b,n) |

For each of the four functions above, your report should include a plot of epsilon as a function of n, using log-log scales.  For each function, choose interesting values of a and b.  Based on these plots you should explain at what rate the error epsilon decreases as a function of n, using "little o" notation.  For example, you may find that for one function epsilon is proportional to 1/n^2.  In this case the error decreases quadratically, i.e. epsilon = o(n^(-2)).

As an appendix to your report, you should submit a printout of your software, with comments and documentation of professional quality. This documentation should be sufficient for another software engineer to maintain the program. Remember that good documentation is necessary but not sufficient.
Comments and user instructions cannot alleviate bad engineering.

Be sure to follow all the rules and guidelines explained in the CSE 130 course description.  Complete academic honesty is required.