| Department of Computer Science and Engineering | CSE 130 |
| University of California at San Diego | Fall 1999 |
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;
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.
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:
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.