The Modified Trapezoid Method¶
Updated April 12
Update on April 8: I recommend first doing this with a fixed number of intervals \(n\) rather than an error tolerance, so comparable to the code for the composite trapezoid rule — inded it could use you function from Task 3 for the composite trapezoid rule.
Then iteration in pursuit of an error tolerance (doubling \(n\) until the estimated error is small enough) could be done as a refinement. This can then by done by my favored approach of:
First, implement with a
for
that does a predetermined number of steps \(m\), computing \(T_1', T_2', T_4', \dots, T_{2^m}'\).Then revise to add an error estimate (e.g the difference between the two most recent approximations) and exit the
for
loop early with abreak
if and when the error estimate is small enough.
A. Write a function based on the Modified Trapezoid Method.¶
to estimate a definite integral with a specified absolute error tolerance. Its input needs a function for the derivative \(Df\), along with other input and output as above for the Composite Trapezoid Rule.
Hint: You already have code for \(T_n\), from Task 3.
B. The Modified Trapezoid Method, without derivatives¶
Write a new version of the function for the Modified Trapezoid Method, that does not input the derivative.
This must therefore use appropriate derivative approximation methods.