computing integrals if this function is stored in module file midpoint_double pywe can compute some integrale cy/dxdy in an interactive shell and demonstrate that the function computes the right numberfrom midpoint_double import midpoint_double def (xy)return * midpoint_double ( reusing code for one-dimensional integrals it is very natural to write twodimensional midpoint method as we did in function midpoint_double when we have the formula ( howeverwe could alternatively askmuch as we did in the mathematicscan we reuse well-tested implementation for one-dimensional integrals to compute double integralsthat iscan we use function midpoint def midpoint(fabn) float( - )/ result for in range( )result + (( / *hresult * return result from sect "twice"the answer is yesif we think as we did in the mathematicscompute the double integral as midpoint rule for integrating xand define xi in terms of midpoint rule over in the coordinate the corresponding function has very short codedef midpoint_double (fabcdnxny)def ( )return midpoint(lambda yf(xy)cdnyreturn midpoint(gabnxthe important advantage of this implementation is that we reuse well-tested function for the standard one-dimensional midpoint rule and that we apply the onedimensional rule exactly as in the mathematics verification via test functions how can we test that our functions for the double integral workthe best unit test is to find problem where the numerical approximation error vanishes because then we know exactly what the numerical answer should be the midpoint rule is exact for linear functionsregardless of how many subinterval we use alsoany linear two-dimensional function xyd px qy will be integrated exactly by the two-dimensional midpoint rule we may pick xyd and create proper test function that can automatically verify our two alternative implementations of the two-dimensional midpoint rule to compute the integral of xywe take advantage of sympy to eliminate the possibility of errors in hand calculations the test function becomes