Problem (taken from Trangenstein, Scientific Computing ):
Solution:
The C++ code "AdaptiveQuadrature.c", which is modified from Prof. Trangenstein's code "GUIAdaptiveQuadrature.C", defines three possible quadrature schemes: Riemann, midpoint and trapezoidal (must be changed in the source file). An external variable "adaptnumber" is defined to keep track the number of adaptive iterations.
The code is run by "./AdaptiveQuadrature n" where n is an integer from 1 to 9 that switches the functions to one of the (a)~(i) cases.
The code output on screen the final integration results I and number of adaptive iterations N. The results using midpoint and trapezoidal rule are shown in this table (epsilon = 0.0000000001):
Though both methods produce consistent integration results to the desired accuracy, no quadrature dominates the other for all types of functions in terms of iteration efficiency.