Tutorial 10
Click the badges above to run this tutorial interactively in your browser without installing anything!
- Binder: Free cloud-based Jupyter environment
- Colab: Google's free Jupyter notebook environment
Topics Covered
This tutorial covers the following topics using Python and SymPy:
- Double integrals over rectangles and general regions
- Order of integration and why it matters for the difficulty of the calculation
- Triple integrals over boxes and solids
- Mass and centre of mass of a lamina and of a solid
Introduction
SymPy evaluates iterated integrals directly: write integrate(f, (y, y_low, y_high), (x, x_low, x_high))
and it works from the innermost variable outwards, exactly as you would by hand.
import sympy as sy
from sympy.abc import x, y, z, t
from sympy import (sqrt, sin, cos, pi, ln, exp, integrate, simplify, diff, expand,
Rational, N, Matrix, S)
sy.init_printing(use_latex=True)
Question 1
Evaluate the iterated integrals.
a.
display(integrate(2*x - y, (y, 2, 3), (x, 1, 2))) # 1/2
b.
display(integrate(x - 5*y, (x, -1, 2), (y, 1, 5))) # -174
c.
display(integrate(2*x - 3*y, (x, 2, 5), (y, 1, 3))) # 6
Question 2
Evaluate over the given region .
a. , is the unit square , .
display(integrate(1 - Rational(1, 2)*x**2 - Rational(1, 2)*y**2,
(y, 0, 1), (x, 0, 1))) # 2/3
b. , where is bounded by and .
The curves meet at and , and on that interval .
# solve over the reals only, so the complex roots are not returned
display(list(sy.solveset(sqrt(x) - x**3, x, domain=S.Reals))) # [0, 1]
display(integrate(4*x*y - y**3, (y, x**3, sqrt(x)), (x, 0, 1))) # 55/156
Question 3
where .
display(integrate(42*y**2 - 12*x, (y, (x - 2)**2, 6), (x, 0, 4))) # 11136
Question 4
over , both ways round.
display(integrate(12*x - 18*y, (x, -1, 4), (y, 2, 3))) # -135
display(integrate(12*x - 18*y, (y, 2, 3), (x, -1, 4))) # -135
Because the region is a rectangle and the integrand is a sum of separate functions of and , both orders give the same answer.
Question 5
Compute the double integrals over the indicated rectangles.
a. ,
display(integrate(6*y*sqrt(x) - 2*y**3, (x, 1, 4), (y, 0, 3))) # 9/2
b. ,
R5 = integrate(y*exp(y**2 - 4*x), (y, 0, sqrt(8)), (x, 0, 2))
display(expand(R5), sy.N(R5, 8)) # -1/4 + e^-8/8 + e^8/8 = 372.36979
The printed solution for 5(b) is a copy-paste of 5(a)'s working. The value is correct, but the integral shown above it is not the one being evaluated.
Question 6
Evaluate the triple integrals.
a.
display(integrate(6*x*y*z, (y, 0, 1), (x, -1, 2), (z, -3, 1))) # -18
b.
display(integrate(x*y, (x, 1, 2), (y, -2, -1), (z, 0, 4))) # -9
Question 7
Evaluate the triple integrals over the given boxes.
a. , , ,
display(integrate(x*y*z**2, (x, 0, 1), (y, -1, 2), (z, 0, 3))) # 27/4
b. , , ,
B7 = integrate(4*x**2*y - z**3, (z, 0, 1), (y, -1, 4), (x, 2, 3))
display(B7) # 755/4
display(sy.N(B7, 8)) # 188.75
The printed solution flips the sign after the -integration, writing instead of , and so obtains . Substituting the -limits gives . Note this integrand is not everywhere positive: it is negative for (for instance at ), so the printed sign flip cannot be argued away by a positivity claim. The correct answer is .
Question 8
Integrate over the volume enclosed by , , and .
The curves and meet at and ; integrating first gives the limits .
V8 = integrate(x*y, (z, 0, x + y), (y, x**2, sqrt(x)), (x, 0, 1))
display(V8) # 3/28
Question 9
Mass of the unit-square lamina with density .
m = integrate(x + y + 2, (x, 0, 1), (y, 0, 1))
display(m) # 3 g
Question 10
Mass and centre of mass of the tetrahedron bounded by and the coordinate planes, with density .
The tetrahedron meets the axes at , and ; projecting onto the -plane gives , and .
ztop = Rational(1, 3)*(6 - x - 2*y)
ytop = Rational(1, 2)*(6 - x)
m = integrate(x**2*y*z, (z, 0, ztop), (y, 0, ytop), (x, 0, 6))
Mxy = integrate(x**2*y*z**2, (z, 0, ztop), (y, 0, ytop), (x, 0, 6)) # about xy-plane
Mxz = integrate(x**2*y**2*z, (z, 0, ztop), (y, 0, ytop), (x, 0, 6)) # about xz-plane
Myz = integrate(x**3*y*z, (z, 0, ztop), (y, 0, ytop), (x, 0, 6)) # about yz-plane
display(m, Mxy, Mxz, Myz) # 108/35, 54/35, 81/35, 243/35
display(simplify(Myz/m), simplify(Mxz/m), simplify(Mxy/m)) # 9/4, 3/4, 1/2
The printed solution labels the last coordinate . By definition , and ; the numbers are right, only the label is wrong.
Extra Learning Resources
Key Concepts to Master
- Fubini's theorem: for a rectangle the order of integration can be swapped freely
- General regions: find the outer limits from the projection, then the inner limits from the bounding curves
- Order matters for effort: some integrands have no elementary antiderivative in one order but are easy in the other
- Triple integrals: integrate the innermost variable first, then work outwards
- Centre of mass: , ,
SymPy Resources
- SymPy
integrate— nested definite integrals - SymPy
Rational— exact fractions for limits such as - SymPy
solve— intersection points of the bounding curves
Common Pitfalls
- Use
Rational(1, 2), not1/2, inside an integrand or SymPy will switch to floats - The inner limits may depend on the outer variables — get the nesting order right
- Watch the sign when the integrand changes sign over the region (as in 1(b), where the answer is )
- Double-check which moment belongs to which coordinate: pairs with