The Recursive Trapezoid Rule, with error control¶
Notes added on Thursday March 25
Write a function that uses the Recursive Trapezoid Rule, \(R_m = T_{2^m}\) to estimate a definite integral with a specified absolute error tolerance.
The input should specify the function \(f\) and interval \([a,b]\), and also the error tolerance.
The output should include the approximate answer, estimated error, and also the number of evaluations of \(f(x)\), as a measure of cost.
Added note:
Recall the formula
\[
T_{2n} = (T_n + M_n)/2
\]
so
\[
R_m = T_{2^m} = \frac{T_{2^{m-1}} + M_{2^{m-1}}}{2}
\]
which makes the evaluations more efficient. Thus, a useful first step is to write a Python function for the Composite Midpoint Rule,
def midpoint(f, a, b, n):
...
return M_n