Skip to main content

Tutorial 13

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:

  • Surface integrals of a vector field: ∬SF⋅dS\iint_{S}\mathbf{F}\cdot d\mathbf{S}
  • Flux across a graph z=g(x,y)z=g(x,y)
  • Orientation: upward versus downward normals
  • Surface integrals of a scalar function: ∬Sf dS\iint_{S}f\,dS
  • Area of a surface and the surface element dSdS

Introduction​

For a surface given as the graph z=g(x,y)z=g(x,y) over a region DD:

∬SF⋅dS=∬DF⋅(−∂g∂xi−∂g∂yj+k)dx dy\iint_{S}\mathbf{F}\cdot d\mathbf{S} =\iint_{D}\mathbf{F}\cdot\left(-\frac{\partial g}{\partial x}\mathbf{i} -\frac{\partial g}{\partial y}\mathbf{j}+\mathbf{k}\right)dx\,dy

For a parametrised surface r(u,v)\mathbf{r}(u,v):

dS=∣∂r∂u×∂r∂v∣du dvdS=\left|\frac{\partial\mathbf{r}}{\partial u}\times\frac{\partial\mathbf{r}}{\partial v}\right|du\,dv

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

def gradient(f, vars=(x, y, z)):
return Matrix([diff(f, q) for q in vars])

Question 1​

Evaluate the surface integral of F=3x2i−2yx j+8k\mathbf{F}=3x^{2}\mathbf{i}-2yx\,\mathbf{j}+8\mathbf{k} over the surface SS that is the graph of z=2x−yz=2x-y over the rectangle [0,2]×[0,2][0,2]\times[0,2].

Here g=2x−yg=2x-y, so the upward normal is (−gx,−gy,1)=(−2,1,1)\left(-g_{x},-g_{y},1\right)=(-2,1,1).

g = 2*x - y
n = Matrix([-diff(g, x), -diff(g, y), 1])
display(n) # <-2, 1, 1>

F = Matrix([3*x**2, -2*y*x, 8])
integrand = simplify((F.subs({z: g})).dot(n))
display(integrand) # -6*x**2 - 2*x*y + 8

display(integrate(integrand, (x, 0, 2), (y, 0, 2))) # -8

∬SF⋅dS=−8\iint_{S}\mathbf{F}\cdot d\mathbf{S}=-8

Question 2​

SS is the triangle with vertices (1,0,0)(1,0,0), (0,2,0)(0,2,0) and (0,1,1)(0,1,1), and F=xyz(i+j)\mathbf{F}=xyz(\mathbf{i}+\mathbf{j}). The triangle is oriented by the downward normal.

The plane through the three vertices is z=−2x−y+2z=-2x-y+2, so with x=ux=u, y=vy=v we get r(u,v)=(u,v,−2u−v+2)\mathbf{r}(u,v)=(u,v,-2u-v+2) and ru×rv=(2,1,1)\mathbf{r}_{u}\times\mathbf{r}_{v}=(2,1,1) — which points upward.

r = Matrix([u, v, -2*u - v + 2])
cross = r.diff(u).cross(r.diff(v))
display(cross) # <2, 1, 1>

F = Matrix([u*v*(-2*u - v + 2), u*v*(-2*u - v + 2), 0]) # xyz (i + j) with z = -2u-v+2
integrand = simplify(F.dot(cross))
display(integrand) # 3*u*v*(-2*u - v + 2)

# the domain D is the triangle with vertices (1,0), (0,2), (0,1): 0<=u<=1, 1-u<=v<=2-2u
upward = integrate(integrand, (v, 1 - u, 2 - 2*u), (u, 0, 1))
display(upward) # 1/10
display(-upward) # -1/10 (downward orientation)

∬SF⋅dS=−110\iint_{S}\mathbf{F}\cdot d\mathbf{S}=-\frac{1}{10}

The sign flip is the whole point of the question: the parametrisation naturally gives the upward orientation, so the answer must be negated to get the downward flux.

Question 3​

The disk z=12z=12, x2+y2≤25x^{2}+y^{2}\le25, with r(x,y,z)=xi+yj+zk\mathbf{r}(x,y,z)=x\mathbf{i}+y\mathbf{j}+z\mathbf{k}.

F = Matrix([x, y, z])
g = 12
n = Matrix([-diff(g, x), -diff(g, y), 1])
display(n) # <0, 0, 1>

integrand = simplify((F.subs({z: g})).dot(n))
display(integrand) # 12

display(integrate(integrand, (y, 0, 5), (x, 0, 5))) # 300 (over the square, for illustration)
display(12 * (pi*5**2)) # 300*pi (area of the disk)

∬Sr⋅dS=∬D12 dx dy=12×25π=300π\iint_{S}\mathbf{r}\cdot d\mathbf{S}=\iint_{D}12\,dx\,dy=12\times25\pi=300\pi

Question 4​

SS is the closed surface made of the upper hemisphere x2+y2+z2=1x^{2}+y^{2}+z^{2}=1, z≥0z\ge0 and its base x2+y2≤1x^{2}+y^{2}\le1, z=0z=0. Find the flux of E=2xi+2yj+2zk\mathbf{E}=2x\mathbf{i}+2y\mathbf{j}+2z\mathbf{k}.

Split S=H∪DS=H\cup D. On the hemisphere the outward unit normal is n=(x,y,z)\mathbf{n}=(x,y,z), and on the base it is −k-\mathbf{k}.

# hemisphere:  E . n = 2(x^2 + y^2 + z^2) = 2  ->  flux = 2 * area(hemisphere)
flux_H = 2 * (2*pi*1**2) # area of a hemisphere of radius 1 is 2*pi
display(flux_H) # 4*pi

# base: E . n = (2x, 2y, 0) . (0, 0, -1) = 0
flux_D = 0
display(flux_H + flux_D) # 4*pi

∬SE⋅dS=4π\iint_{S}\mathbf{E}\cdot d\mathbf{S}=4\pi

Question 5​

Area of the ellipse cut on the plane 2x+3y+6z=602x+3y+6z=60 by the cylinder x2+y2=2xx^{2}+y^{2}=2x.

zplane = (60 - 2*x - 3*y)/6
dS = sqrt(1 + diff(zplane, x)**2 + diff(zplane, y)**2)
display(simplify(dS)) # 7/6

display(simplify(sy.factor(x**2 + y**2 - 2*x))) # x**2 - 2*x + y**2 = (x-1)**2 + y**2 - 1 -> unit circle
display(Rational(7, 6) * pi) # 7*pi/6

The projection DD is the unit circle (x−1)2+y2≤1\left(x-1\right)^{2}+y^{2}\le1 with area π\pi, so

Area=∬D76 dx dy=76π\text{Area}=\iint_{D}\frac{7}{6}\,dx\,dy=\frac{7}{6}\pi

Question 6​

∬Sx dS\displaystyle\iint_{S}x\,dS where SS is the part of x2+y2+z2=a2x^{2}+y^{2}+z^{2}=a^{2} in the first octant.

In spherical coordinates dS=a2sin⁡θ dϕ dθdS=a^{2}\sin\theta\,d\phi\,d\theta and x=acos⁡ϕsin⁡θx=a\cos\phi\sin\theta, so the integral becomes a3∬cos⁡ϕsin⁡2θ dϕ dθa^{3}\iint\cos\phi\sin^{2}\theta\,d\phi\,d\theta over 0≤ϕ≤π20\le\phi\le\frac{\pi}{2}, 0≤θ≤π20\le\theta\le\frac{\pi}{2}.

I = integrate(a**3 * cos(phi)*sin(theta)**2, (phi, 0, pi/2), (theta, 0, pi/2))
display(simplify(I)) # pi*a**3/4

∬Sx dS=πa34\iint_{S}x\,dS=\frac{\pi a^{3}}{4}

Question 7​

∬SdSx2+y2+z2\displaystyle\iint_{S}\frac{dS}{\sqrt{x^{2}+y^{2}+z^{2}}} over the cylinder r(u,v)=(acos⁡u, asin⁡u, v)\mathbf{r}(u,v)=(a\cos u,\ a\sin u,\ v), 0≤u≤2π0\le u\le2\pi, 0≤v≤H0\le v\le H.

# radius and height are positive, so sqrt(a^2) simplifies to a
a = Symbol('a', positive=True)
H = Symbol('H', positive=True)

rv = Matrix([a*cos(u), a*sin(u), v])
ru, rv_ = rv.diff(u), rv.diff(v)
display(ru, rv_)

cross = ru.cross(rv_)
display(cross) # <a*cos(u), a*sin(u), 0>
dS = sqrt(cross.dot(cross))
display(simplify(dS)) # a

integrand = dS / sqrt(a**2 + v**2) # x^2+y^2+z^2 = a^2 + v^2
I = integrate(integrand, (v, 0, H), (u, 0, 2*pi))
display(simplify(I)) # 2*pi*a*asinh(H/a)

# asinh(H/a) is the same as ln((H + sqrt(a^2 + H^2))/a)
display(simplify(I.rewrite(ln) - 2*pi*a*ln((H + sqrt(a**2 + H**2))/a))) # 0
∬SdSx2+y2+z2=2πaln⁡(H+a2+H2a)\iint_{S}\frac{dS}{\sqrt{x^{2}+y^{2}+z^{2}}} =2\pi a\ln\left(\frac{H+\sqrt{a^{2}+H^{2}}}{a}\right)

Extra Learning Resources​

Key Concepts to Master​

  1. Flux across a graph: use the normal (−gx,−gy,1)\left(-g_{x},-g_{y},1\right) for the upward orientation
  2. Orientation matters: a downward normal flips the sign of the flux
  3. Surface element from a parametrisation: dS=∣ru×rv∣du dvdS=\left|\mathbf{r}_{u}\times\mathbf{r}_{v}\right|du\,dv
  4. Scalar surface integral: ∬Sf dS\iint_{S}f\,dS — substitute the surface into ff and multiply by dSdS
  5. Closed surfaces: split into the parts (hemisphere plus base) and add the fluxes

SymPy Resources​

  • SymPy cross — ru×rv\mathbf{r}_{u}\times\mathbf{r}_{v}
  • SymPy integrate — the resulting double integral
  • SymPy asinh — asinh⁡(v/a)=ln⁡ ⁣(v+a2+v2a)\operatorname{asinh}(v/a)=\ln\!\left(\dfrac{v+\sqrt{a^{2}+v^{2}}}{a}\right)

Common Pitfalls​

  • Always check the direction of ru×rv\mathbf{r}_{u}\times\mathbf{r}_{v} before deciding on the sign
  • sqrt(cross.dot(cross)) — the magnitude of a vector is the square root of its dot product with itself
  • When the surface lies in a plane z=g(x,y)z=g(x,y), substitute z=gz=g into F\mathbf{F} before taking the dot product
  • For a closed surface, the outward normal points away from the enclosed volume on every face