# Numerical Integration Lab Exercise

The file Integrate.java contains a program to do some numerical integration. Currently the program implements the composite Simpson's rule and has built in 6 functions that are in Computer Exercises 8.1 - 8.4 on page 378 of the text. The correct values for each of the 6 integrals are also built in so that actual errors in the approximations can be studied. Copy the file to your directory then do the following:

1. Implement the composite Midpoint Rule and the composite Trapezoid Rule. The stubs for both these methods are already in the program. For each, 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 program to compute and print this error estimate. 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. Now use the program to do problem 8.2(a). What happens when you put 0 and 1 in as the limits of integration? The problem is that this is an improper integral -- the function in the integrand has a singularity at 0 because log(0) is undefined. Suggest a way to evaluate this integral (using the program -- you should not need to change the program) and test your method.

6. The integral in #8.4(e) is also an improper integral.
1. Why?
2. If you run the program to evaluate this integral and put in -9 and 100 as the interval [a,b], what values of n give problems?
3. What happens for other values of n? Is the conjecture about the value of the value of the integral supported or not?
4. Describe a way to use the program to test the conjecture about the value of the integral. Is the conjecture supported?
5. Because the interval for problem #8.4(e) is so wide you may not have seen just how much trouble the singularity at 0 can cause. Run the program for the same function but for the interval [-1, 1]. Try n = 100, then n = 105. What happened and why? (The correct value of the integral is 4. Note that the error is no longer meaningful because it is computed using 26 as the actual value.)
6. By symmetry, the integral of the function in 8.4(e) over the interval [-1,1] is 2 times the integral over [0,1]. Use the program to evaluate this integral. (It is still an improper integral so you can't use the limit 0.) Does it work well? For what values of n do you get a decent approximation? For what values is the approximation way off?