| Department of Computer Science and Engineering | CSE 130 |
| University of California at San Diego | Spring 2002 |
The purpose of this assignment is to make you understand some important differences and similarities between the C and Pascal languages. The task 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. You must implement lriemann and rriemann with the precise signatures specified above. This means that these functions must be able to integrate any well-defined real -> real function, over any input range that is meaningful.
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;
Your programs should not ask for keyboard input. Instead your main program should implement the test cases to be announced on Discus. We are not providing sample inputs or outputs now, since in real-world projects usually these are not provided. For now, use your knowledge of calculus to invent your own test cases.
To submit your software, you will use the UCSD turnin software. Check Discus for detailed instructions. Your code must follow all the principles of good software engineering that you have learned in other courses. Handling error cases (for example division by zero) is part of good software engineering, for you to design. We are not providing this level of detail in the assignment description.
You should use double precision and you may use standard math libraries such as math.c in C.
You should also submit a short paper at the start of class on April 15. The paper should be based on your experience doing the project. In the paper you must explain the important ways in which Pascal is "higher-level" while C is more flexible. Issues to discuss include:
The paper must follow the principles of good writing thatwriting that you have learned in previous courses. Complete academic honesty is required. Even the slightest degree of plagiarism is totally unacceptable. This assignment is strictly individual. Later projects will be team projects.