doubleapproximations to a definite integral computed using the composite midpoint, trapezoid, and Simpson's rules, respectively, using a regular partition. Each method should use parameters
func(a Function object representing the integrand),
b(the endpoints of the integration interval), and
n(the number of subintervals to be used).
simpmethod should have a one-line body that combines the values returned by
mainmethod that uses
simpto compute an integral and then outputs the following quantities for each quadrature rule:
n, the approximation to the integral provided by the rule, the exact error in the approximation, and the ratio of the exact error in the approximation using
n/2subintervals to that using
nsubintervals. These quantities should be output for
n = 1, 2, 4, 8, ...EXCEPT that the ratio cannot be output for
n=1(since there is no previous result with which to form a ratio). Your program should continue doubling
nand applying a rule to an integral until the absolute value of the exact error found when applying the rule is less than
1.0e-8. For a given integral, all results for the midpoint rule should be output first, then all results for the trapezoid rule, and finally all results for Simpson's rule (i.e. thus, each integral produces 3 paragraphs of output, one for each rule). Run your program (four separate times if you like) using the four integrand-interval pairs below:
f1(x) = sin(x), on [0, Pi]
f2(x) = 2 exp(x)/[exp(5) - exp(1)], on [1, 5]
f3(x) = 7 x5/2, on [0, 1]
f4(x) = 3 x1/2, on [0, 1]Briefly discuss your findings, especially the exact error ratio and what may have caused it to deviate from the expected ratio. Please ensure that you submit a hard copy of all output (whether or not your program was run separately for each integral) and that your output is neatly formatted .
qRomb) as well as a
mainmethod that calls
qRomb. First, modify
qRombso that it counts the number of function evaluations performed in computing an integral. Next, add a Java method with the header below to the
public static double adaptSimp(Function func, double a, double b, double tol)More will be said about this method in class, but basically it should call a recursive method (name it
adSimpRec) that adaptively applies Simpson's rule to an integral to obtain an approximation that (we hope) has an absolute error less than
tol. Your code should be written so that no unnecessary function evaluations are done, and it should count the number of function evaluations performed in computing an integral.
TestQuadfurther so that it applies the
adaptSimpmethods, in an attempt to compute an integral within a tolerance of
1.0e-12, to each of the four integrand-interval pairs given above as well as the three pairs given below. Your program should output, for each method, the integral approximation returned by the method, the exact absolute error in the approximation, and the number of function evaluations required. Then, use these results to make (possibly by hand or with a word processor) a table indicating the absolute error and the number of function evaluations for each method applied to each integrand-interval pair. Based on all your results, compare the reliability and efficiency of the
adaptSimpmethods. Also, try to explain any cases where one method or the other performs badly or is unusually successful.
f5(x) = .01/(2x2 - 23/2x + 1.001), on [0, 1]
f6(x) = .01 x9, on [1, 2]
f7(x) = 1 - cos(32x), on [0, 2Pi]Use Maple to calculate (to 16 significant digits) the definite integral above involving
f5(x)(so that you can calculate exact absolute errors for it). Alternatively, the following formula can be used in your program to calculate the exact value of the integral involving
.01[arctan[(21/2-1)/C1] + arctan(1/C1)]/C2, where C1 = (.001)1/2 and C2 = (.002)1/2.
On or before 5:00 p.m. on the due date, hand in hard copies of all code, all output, and all written work. Also, by the same deadline, send me an e-mail with all your Java files attached to it.