This assignment is due before the end of the day on Monday, September 7. Those of you planning a wild Labor Day weekend should consider doing this assignment before the weekend.
This week we will learn how to do something that is actually useful with the computer, namely integrate a function numerically.
One of the things that we want you to learn about is the effects of the limits on precision of computer arithmetic on your results. Therefore, even if you already know enough about C to know about ``double'' variables, please continue to use ``float'' variables this week. Next week we will switch over to using double.
Once again, remember that your homework submission is a report which should contain your programs, but must also explain what each program does, what the numerical methods are, how you tested it, some sample input and output, and your conclusions. (Think about your laboratory reports in other classes -- you wouldn't just turn in a table of your measurements!) We do want you to turn in your (properly commented) programs for all three methods.
1) Write a program to calculate
Once you have this program working, copy it and modify it to use the midpoint rule. Then, copy it again and modify it to use trapezoid rule.
Using a=0 and b=1.5, make a table of the values your programs give (all three methods) using the number of bins 2, 4, 6, 10, 20, 50, 100, 200, 1000, 10000, 100000 and 1000000.
Compare your results to the correct value of the integral -- you should be able to do this integral analytically. Then study the dependence of the error on the bin size. See the table in section 3.11 of the class notes for an example of how to go about this. In particular, note the last column where the error is rescaled to see if it follows the expected power law. Then make a log-log plot of the absolute value of the difference of your results from the correct value versus the number of intervals. You should turn in a postscript, PNG, or PDF version of the plot. Discuss whether or not your results are what should be expected.
(Assignment continues on next page)
Note: It may not matter for the way you choose to do the plotting, but beware that the C function for taking the absolute value of a floating point number is fabs(). The function abs() only works for integers.
2) Use your program to calculate
Optional, Not for credit: If you want to do something only slightly harder, modify your program again to use Simpson's rule. Then find the error scaling in this method and add it to your analysis, including the log-log plot.