Skip to main content

Tutorial 11

Binder Open In Colab

Interactive Notebooks

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:

  • Polar coordinates: converting a Cartesian integral and evaluating it
  • Volume below a surface and between two cylinders
  • Spherical coordinates: volume between a sphere and a cone
  • Area of a polar region r=f(θ)r=f(\theta)
  • Cylindrical coordinates: curved wedges and setting up triple integrals
  • Mass with a variable density

Introduction​

The three coordinate systems and their volume elements:

SystemSubstitutiondVdV
Polarx=rcos⁡θ, y=rsin⁡θx=r\cos\theta,\ y=r\sin\thetadA=r dr dθdA=r\,dr\,d\theta
Cylindricalx=rcos⁡θ, y=rsin⁡θ, z=zx=r\cos\theta,\ y=r\sin\theta,\ z=zdV=r dz dr dθdV=r\,dz\,dr\,d\theta
Sphericalx=ρsin⁡ϕcos⁡θ, y=ρsin⁡ϕsin⁡θ, z=ρcos⁡ϕx=\rho\sin\phi\cos\theta,\ y=\rho\sin\phi\sin\theta,\ z=\rho\cos\phidV=ρ2sin⁡ϕ dρ dϕ dθdV=\rho^{2}\sin\phi\,d\rho\,d\phi\,d\theta

The factor rr (or ρ2sin⁡ϕ\rho^{2}\sin\phi) is the Jacobian — forgetting it is the single most common mistake in this chapter.

import sympy as sy
from sympy.abc import x, y, z, t, r, theta, phi, rho, a, H, k
from sympy import (sqrt, sin, cos, tan, sec, pi, ln, exp, log, integrate, simplify,
diff, Rational, N, Matrix, Symbol)
sy.init_printing(use_latex=True)

Question 1​

Convert each Cartesian integral to polar coordinates and evaluate.

a. ∫−11∫01−x2dy dx\displaystyle\int_{-1}^{1}\int_{0}^{\sqrt{1-x^{2}}}dy\,dx

The region is the upper half of the unit disc: 0≤r≤10\le r\le1, 0≤θ≤π0\le\theta\le\pi.

I = integrate(r, (r, 0, 1), (theta, 0, pi))
display(I) # pi/2

b. ∫02∫0xy dy dx\displaystyle\int_{0}^{2}\int_{0}^{x}y\,dy\,dx

The region is the triangle 0≤y≤x0\le y\le x, 0≤x≤20\le x\le2, i.e. 0≤θ≤π/40\le\theta\le\pi/4.

display(integrate(y, (y, 0, x), (x, 0, 2)))      # 4/3 (direct)
I = integrate(r*sin(theta)*r, (r, 0, 2/cos(theta)), (theta, 0, pi/4))
display(simplify(I)) # 4/3 (polar)

c. ∫−11∫−1−x21−x22(1+x2+y2)2dy dx\displaystyle\int_{-1}^{1}\int_{-\sqrt{1-x^{2}}}^{\sqrt{1-x^{2}}}\frac{2}{\left(1+x^{2}+y^{2}\right)^{2}}dy\,dx

The region is the whole unit disc, and 1+x2+y2=1+r21+x^{2}+y^{2}=1+r^{2}.

I = integrate(2/(1 + r**2)**2 * r, (r, 0, 1), (theta, 0, 2*pi))
display(simplify(I)) # pi

d. ∫0ln⁡2∫0(ln⁡2)2−y2ex2+y2 dx dy\displaystyle\int_{0}^{\ln 2}\int_{0}^{\sqrt{(\ln 2)^{2}-y^{2}}}e^{\sqrt{x^{2}+y^{2}}}\,dx\,dy

The region is the part of the disc of radius ln⁡2\ln 2 in the first quadrant, so 0≤r≤ln⁡20\le r\le\ln 2 and 0≤θ≤π/20\le\theta\le\pi/2, and er2=ere^{\sqrt{r^{2}}}=e^{r}.

I = integrate(exp(r)*r, (r, 0, ln(2)), (theta, 0, pi/2))
display(simplify(I)) # pi*(log(2) - 1/2)
display(simplify(I - pi/2*(ln(4) - 1))) # 0

I=π2(ln⁡4−1)I=\frac{\pi}{2}\left(\ln 4-1\right)

Question 2​

∬(1−x2−y2)dA\displaystyle\iint\left(1-x^{2}-y^{2}\right)dA over the unit disc.

I = integrate((1 - r**2)*r, (r, 0, 1), (theta, 0, 2*pi))
display(simplify(I)) # pi/2

Question 3​

Volume below z=y2x2+y2z=\dfrac{y^{2}}{x^{2}+y^{2}}, above the xyxy-plane, between x2+y2=1x^{2}+y^{2}=1 and x2+y2=2x^{2}+y^{2}=2.

In polar coordinates z=sin⁡2θz=\sin^{2}\theta, so the volume is ∫02π∫12sin⁡2θ  r dr dθ\int_{0}^{2\pi}\int_{1}^{\sqrt{2}}\sin^{2}\theta\;r\,dr\,d\theta.

I = integrate(sin(theta)**2*r, (r, 1, sqrt(2)), (theta, 0, 2*pi))
display(simplify(I)) # pi/2

Question 4​

Volume between the sphere x2+y2+z2=1x^{2}+y^{2}+z^{2}=1 and the cone z=x2+y2z=\sqrt{x^{2}+y^{2}}.

In spherical coordinates the cone is ϕ=π/4\phi=\pi/4, so 0≤θ≤2π0\le\theta\le2\pi, 0≤ϕ≤π/40\le\phi\le\pi/4, 0≤ρ≤10\le\rho\le1.

V = integrate(rho**2*sin(phi), (rho, 0, 1), (phi, 0, pi/4), (theta, 0, 2*pi))
display(simplify(V)) # pi*(2 - sqrt(2))/3

V=π3(2−2)V=\frac{\pi}{3}\left(2-\sqrt{2}\right)

Question 5​

Area of the region bounded by r=3cos⁡θr=3\cos\theta.

The curve is the circle (x−32)2+y2=94\left(x-\frac{3}{2}\right)^{2}+y^{2}=\frac{9}{4}, traced for −π2≤θ≤π2-\frac{\pi}{2}\le\theta\le\frac{\pi}{2}; by symmetry we integrate from 00 to π2\frac{\pi}{2} and double.

A = 2*integrate(r, (r, 0, 3*cos(theta)), (theta, 0, pi/2))
display(simplify(A)) # 9*pi/4
note

A naive 0≤θ≤π0\le\theta\le\pi setup does not describe the region correctly, because r=3cos⁡θ<0r=3\cos\theta<0 for π2<θ≤π\frac{\pi}{2}<\theta\le\pi while rr must be non-negative. It is still worth knowing that this setup does not give 00: the inner integral is a square, ∫03cos⁡θr dr=92cos⁡2θ\int_{0}^{3\cos\theta}r\,dr=\frac{9}{2}\cos^{2}\theta, so a negative upper limit cannot make it vanish. Do not rely on a sign argument here — split the region and double it.

Question 6​

∭y dV\displaystyle\iiint y\,dV over the solid bounded by z=4−x2−y2z=4-x^{2}-y^{2} in the first octant.

# in cylindrical coordinates y = r*sin(theta) and dV = r dz dr dtheta
V = integrate(r*sin(theta)*r, (z, 0, 4 - r**2), (r, 0, 2), (theta, 0, pi/2))
display(simplify(V)) # 64/15

Note the integrand in cylindrical coordinates: y dV=y⋅r dz dr dθ=rsin⁡θ⋅r dz dr dθy\,dV=y\cdot r\,dz\,dr\,d\theta=r\sin\theta\cdot r\,dz\,dr\,d\theta.

Question 7​

Cylindrical coordinates: volume of the wedge cut from the cylinder (x−2)2+y2=4(x-2)^{2}+y^{2}=4 by z=0z=0 and z=−yz=-y.

The cylinder becomes r=4cos⁡θr=4\cos\theta and z≤−yz\le-y forces y≤0y\le0, so 3π2≤θ≤2π\frac{3\pi}{2}\le\theta\le2\pi.

V = integrate(r, (z, 0, -r*sin(theta)), (r, 0, 4*cos(theta)), (theta, 3*pi/2, 2*pi))
display(simplify(V)) # 16/3

Question 8​

Set up (do not evaluate) the triple integral for the region EE inside r=2sin⁡θr=2\sin\theta, above z=0z=0 and below the sphere of radius 44.

The bounds are 0≤θ≤π0\le\theta\le\pi, 0≤r≤2sin⁡θ0\le r\le2\sin\theta and 0≤z≤16−r20\le z\le\sqrt{16-r^{2}}, so

∭Ef(r,θ,z) dV=∫0π∫02sin⁡θ∫016−r2f(r,θ,z) r dz dr dθ\iiint_{E}f(r,\theta,z)\,dV=\int_{0}^{\pi}\int_{0}^{2\sin\theta}\int_{0}^{\sqrt{16-r^{2}}} f(r,\theta,z)\,r\,dz\,dr\,d\theta
ztop = sqrt(16 - r**2)
display(ztop) # sqrt(16 - r**2) : the upper z-limit
display(sy.Integral(sy.Function('f')(r, theta, z)*r, (z, 0, ztop), (r, 0, 2*sin(theta)), (theta, 0, pi)))

Question 9​

Volume of the solid bounded by z=2z=2 and z=x2+y2z=\sqrt{x^{2}+y^{2}}.

V = integrate(r, (z, r, 2), (r, 0, 2), (theta, 0, 2*pi))
display(simplify(V)) # 8*pi/3

Question 10​

Spherical coordinates: volume outside ρ=2cos⁡ϕ\rho=2\cos\phi and inside ρ=2\rho=2 with ϕ∈[0,π/2]\phi\in[0,\pi/2].

V = integrate(rho**2*sin(phi), (rho, 2*cos(phi), 2), (phi, 0, pi/2), (theta, 0, 2*pi))
display(simplify(V)) # 4*pi

Question 11​

Mass of the solid bounded by z=2z=2 and z=x2+y2z=\sqrt{x^{2}+y^{2}} when the density is proportional to the square of the distance from the origin, δ=kρ2\delta=k\rho^{2}.

M = integrate(k*rho**2 * rho**2*sin(phi), (rho, 0, 2/cos(phi)), (phi, 0, pi/4), (theta, 0, 2*pi))
display(simplify(M)) # 48*k*pi/5

M=48kπ5M=\frac{48k\pi}{5}

Question 12​

Mass of TT, bounded by y=x2+z2y=x^{2}+z^{2} and y=4y=4, with density ρ(x,y,z)=y\rho(x,y,z)=y.

Using cylindrical coordinates with the axis along yy, we have x=rcos⁡θx=r\cos\theta, z=rsin⁡θz=r\sin\theta and dV=r dy dr dθdV=r\,dy\,dr\,d\theta with r2≤y≤4r^{2}\le y\le4.

M = integrate(y*r, (y, r**2, 4), (r, 0, 2), (theta, 0, 2*pi))
display(simplify(M)) # 64*pi/3

M=64π3M=\frac{64\pi}{3}


Extra Learning Resources​

Key Concepts to Master​

  1. Always include the Jacobian: rr for polar/cylindrical, ρ2sin⁡ϕ\rho^{2}\sin\phi for spherical
  2. Recognising a disc: x2+y2≤a2x^{2}+y^{2}\le a^{2} becomes 0≤r≤a0\le r\le a, 0≤θ≤2π0\le\theta\le2\pi
  3. Circles through the origin: r=2acos⁡θr=2a\cos\theta (centre on the xx-axis) and r=2asin⁡θr=2a\sin\theta (centre on the yy-axis)
  4. Cone →\to spherical: z=x2+y2z=\sqrt{x^{2}+y^{2}} is ϕ=π/4\phi=\pi/4
  5. Plane z=cz=c in spherical: ρ=csec⁡ϕ\rho=c\sec\phi

SymPy Resources​

Common Pitfalls​

  • Forgetting the Jacobian rr or ρ2sin⁡ϕ\rho^{2}\sin\phi — the most common error in this chapter
  • rr must be non-negative; a region such as r=3cos⁡θr=3\cos\theta only exists where cos⁡θ≥0\cos\theta\ge0
  • In spherical coordinates the polar angle is ϕ\phi (from the zz-axis) and the azimuthal angle is θ\theta — don't swap them
  • When the symmetry axis is not zz (Q12), relabel the cylindrical coordinates accordingly