Numerical Integration Assignment

Due Tuesday, April 20, 2004 by 5pm

The file contains a program to do some numerical integration. Currently the program implements the composite Trapezoid rule and Simpson's rule and has built in 6 functions that are in Computer Exercises 8.1, 8.3 on page 378 of the text plus two other functions. The correct values for each of the 6 integrals are also built in (for the specific limits of integration given in the problems) so that actual errors in the approximations can be studied. (NOTE: The program also has the Romberg method in it - we probably don't have time to talk about Romberg but you can try it out.) Copy the file to your directory then do the following:

  1. Implement the composite Midpoint Rule. The stub for the method is already in the program. Replace the "return 0" statement with the code.

  2. Use the program to do exercise 8.1(a). Basically the exercise is asking you to analyze the error -- to compare the error in the three methods, to relate the error for each method to h (the step size which is (b - a)/n), to determine when decreasing h (increasing n) does no good. In answering these questions also think about the theoretical results for error (for example, the error in midpoint and trapezoid have a nice theoretical relationship) and see if these results hold true in practice. Get output from the program to support your answers (don't waste paper -- decide what output shows what you want then print just that). (Be sure to actually write some answers -- I don't want just output with no analysis!)

  3. In class (and the book), we derived a way of using the midpoint rule and the trapezoid rule to estimate the error in the midpoint rule (and hence also in trapezoid since the two are related). Add code to the integrate method to compute and print this error estimate. (Print it after the table showing the results of the three composite methods.) Determine how well it works for various values of n.

  4. Use the program to evaluate the integrals in problem 8.3 using several values of n (to get different mesh sizes as suggested in the problem). Answer the same questions about error and accuracy of the methods that you answered in 8.1(a) -- explain any unexpected results.

  5. Implement the Adaptive Simpson method. To do this you need to implement the recursive AdaptSimpson method and add a call to that method in the integrateAdapt method.

  6. Use the Adaptive Simpson method to do 8.1(c). The AdaptSimpson method prints out the points sampled so you can use that to plot the graph requested.

  7. Use the Adaptive Simpson method on the integral in the picture handed out (this is function 6 in the program). The limits of integration (endpoints) are 1 and 3. Compare your results to those in the picture.

  8. Implement the Monte Carlo method of integration.

  9. Use the Monte Carlo method to do problem 8.1(d). Of particular interest is the relationship between the number of points and the error AND a comparison of the amount of work for this method compared to the others.

  10. Function 2 in the program is f(x) = e^(sin(x) + x^2)/ln(x). Try the different methods on the interval [3.2, 5.9]. And compare the results (note that the actual answer is approximately 4.09e^13 so the actual errors will often be huge even when the relative error is not too bad. Hence, you should use relative error - either have the program print out relative error or compute it yourself from the absolute error -- in discussing the merits of the algorithms). In particular, explain what happens when you use the adaptive simpson method (your program may very well produce a segmentation fault) and Monte Carlo.
Hand in: A printout of your final program and your answers to the questions. Email a copy of the program to