implementation we follow the advice and lessons learned from the implementation of the trapezoidal method and make function midpoint(fabn(in file midpoint pyfor implementing the general formula ( )def midpoint(fabn) float( - )/ result for in range( )result + (( / *hresult * return result we can test the function as we explained for the similar trapezoidal method the error in our particular problem dt with four intervals is now about in contrast to for the trapezoidal rule this is in fact not accidentalone can show mathematically that the error of the midpoint method is bit smaller than for the trapezoidal method the differences are seldom of any practical importanceand on laptop we can easily use and get the answer with an error of about in couple of seconds comparing the trapezoidal and the midpoint methods the next example shows how easy we can combine the trapezoidal and midpoint functions to make comparison of the two methods in the file compare_ integration_methods pyfrom trapezoidal import trapezoidal from midpoint import midpoint from math import exp lambda yexp(- ** print midpoint trapezoidalfor in range( ) ** midpoint(gabnt trapezoidal(gabnprint '% (nmtnote the efforts put into nice formatting the output becomes midpoint trapezoidal