CSC270S, 1997, St. George Campus Assignment 1 Due Friday, January 30, 1998 at BEGINNING of tutorial A Numerical Integration Program You are to implement three methods of numerical integration: Riemann, trapezoid, and Simpson's. The methods are quite similar, so most of the code you write for one method can be used for the other two. You'll be provided with a `skeleton program' and will have to write code for the bodies of three functions, one for each integration method. Make a directory in your account and copy the skeleton file into it: % cd % mkdir a1 % cd a1 % cp ~jstewart/270/hwk1/integrate.c . ^ Note the period. Don't forget it! Compile and test the skeleton program: % gcc integrate.c -o integrate % integrate usage: integrate method a b n coefficients - `method' is one of: r (Riemann), t (trapezoid), or s (Simpson) - `a' and `b' define the interval of integration - `n' is the number of intervals - `coefficients' define the polynomial to integrate, list in order - of decreasing power (e.g. t^2, then t^1, then t^0) % integrate s 1 4 100 12.3 -4.7 0 1 0 method: SIMPSON range: [1,4] intervals: 100 polynomial: 12.3 t^4 + -4.7 t^3 + 0 t^2 + 1 t^1 + 0 t^0 computed integral = 0 Note that the computed integral is 0. That's because the integration code still has to be written in the program. Programming Read and understand the complete program, integrate.c. Implement the three integration methods by adding code to the three corresponding functions in integrate.c. You do not need to add code outside those functions, but you may do so if you wish and if you document your additions. Provide good comments in your code, including a comment above each of the three functions. Read the newsgroup and POST ALL OF YOUR QUESTIONS TO THE NEWSGROUP. Testing Test all three integrations methods with the two functions provided on the Web page. Test all three integration methods with one other function that you choose. Each of these nine tests should be run with 10, 100, and 1000 intervals. For each of the nine tests, provide one separate page of program output (captured from the screen). On that page, calcluate the exact value of the integral and, for each of 10, 100, and 1000 intervals, the absolute error and the relative error. Report Write a short report (at most one page long) comparing the three methods. From your test results, discuss their relative speed and their relative accuracies. Do certain methods performs very accurately for certain classes of polynomials? For each method, how does the accuracy increase as the number of intervals increases by a factor of 2, 4, 8, and so on? Discuss any other interesting things that you discovered. For the function that you chose for testing, write one or two sentences explaining what interesting characteristic of numerical integration is demonstrated by that function. You should have chosen an interesting function. Hand-in details Hand in the following: - the cover page (included below) - a hardcopy printout of your program, - nine pages, one for each of the test functions - a one-page report Put this into an ENVELOPE. Write the following on the outside of the envelope: - your CDF account name - your name (with surname underlined) - your tutorial - your student number Your programs must also be submitted electronically by the deadline. You must submit your integrate.c program by executing EXACTLY THIS COMMAND: % submit -N a1 csc270h integrate.c You may, if you wish, also submit a README file that the tutor will read. For more information on the submit command, type `man submit' on CDF. The tutors will compile and run your program. MAKE SURE that the following command works with the program that you submit: % gcc -o integrate integrate.c % integrate ... YOU WILL LOSE MARKS if you don't follow these submission instructions exactly. This is because the tutors will be marking more than 300 of these assignments and any deviations from these instructions will cost them time and frustration. Please help to keep the tutors happy. ------------------------------------------------------------------------ COVER SHEET FOR ASSIGNMENT 1 CDF account name: Surname: Given Name(s): Student Number: TA's name: Tutorial location: I declare that this assignment is my own work and is submitted in accordance with the University of Toronto Code of Behavior on Academic Matters, the Code of Student Conduct, and the guidelines for avoiding plagiarism described in the course syllabus. I discussed this assignment with the following people: Signature ------------------------------------------------------------------------ GRADING Program Correctness / 20 Style (including comments) / 5 Test output (nine pages) / 5 Report Content / 10 Style and readability / 5 ----------- Total / 45