double and triple integrals def test_midpoint_double()"""test that linear function is integrated exactly ""def (xy)return * import sympy xy sympy symbols(' 'i_expected sympy integrate( (xy)(xab)(ycd)test three casesnx ny for nxny in ( )( )( )i_computed midpoint_double (fabcdnxnyi_computed midpoint_double (fabcdnxnytol - #print i_expectedi_computed i_computed assert abs(i_computed i_expectedtol assert abs(i_computed i_expectedtol let test functions speak upif we call the above test_midpoint_double function and nothing happensour implementations are correct howeverit is somewhat annoying to have function that is completely silent when it works are we sure all things are properly computedduring development it is therefore highly recommended to insert print statement such that we can monitor the calculations and be convinced that the test function does what we want since test function should not have any print statementwe simply comment it out as we have done in the function listed above the trapezoidal method can be used as alternative for the midpoint method the derivation of formula for the double integral and the implementations follow exactly the same ideas as we explained with the midpoint methodbut there are more terms to write in the formulas exercise asks you to carry out the details that exercise is very good test on your understanding of the mathematical and programming ideas in the present section the midpoint rule for triple integral theory once method that works for one-dimensional problem is generalized to two dimensionsit is usually quite straightforward to extend the method to three dimensions this will now be demonstrated for integrals we have the triple integral zb zd zf xyz/dzdydx