6.7 Double and Triple Integrals
161
Let Test Functions Speak Up?
If we call the above test_midpoint_double function and nothing happens,
our implementations are correct. However, it is somewhat annoying to have
a function that is completely silent when it works—are we sure all things are
properly computed? During development it is therefore highly recommended
to insert a print command such that we can monitor the calculations and be
convinced that the test function does what we want. Since a test function
should not have any print command, we 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 a formula for the double integral and the implementations follow
exactly the same ideas as we explained with the midpoint method, but there are
more terms to write in the formulas. Exercise 6.13 asks you to carry out the details.
That exercise is a very good test on your understanding of the mathematical and
programming ideas in the present section.
6.7.2 The Midpoint Rule for a Triple Integral
Theory Once a method that works for a one-dimensional problem is generalized
to two dimensions, it is usually quite straightforward to extend the method to three
dimensions. This will now be demonstrated for integrals. We have the triple integral
b
a
d
c
f
e
g(x, y, z)dzdydx
and want to approximate the integral by a midpoint rule. Following the ideas for the
double integral, we split this integral into one-dimensional integrals:
p(x, y) =
f
e
g(x, y, z)dz
q(x) =
d
c
p(x, y)dy
b
a
d
c
f
e
g(x, y, z)dzdydx =
b
a
q(x)dx
Précédent

- 182/350

Suivant