
\section{The Divergence Theorem}
In Section \ref{sec:lecture42}, we used Green's Theorem to give a special case of the Divergence Theorem in two dimensions. This section develops the corresponding three-dimensional Divergence Theorem, which is the following result. 

\begin{theorem}\label{43thm:divergence}
Let $D \subset \mathbb{R}^3$ be a domain bounded by a piecewise smooth closed surface $\mathcal{S}$, with unit normal vector $\mathbf{N}$ pointing out of $D$ at all points on $\mathcal{S}$.  If the vector field $\mathbf{F}$ is $C^1$ on some open set containing $D$, then
\begin{equation}\label{43eq:divergencethmstatement}
\iiint_{D} \divg \mathbf{F} \, dV = \oiint_{\mathcal{S}} \mathbf{F} \cdot \mathbf{N} \, dS.
\end{equation}
\end{theorem}

Similar to the loop notation ``$\oint_{\mathcal{C}}$'' for integrals taken over closed curves, the notation ``$\oiint_{\mathcal{S}}$'' tells us that we are integrating over a \textit{closed} surface in $\mathbb{R}^3$.



\subsection{Typical Usage of the Divergence Theorem}
Let us first see some typical applications of the Divergence Theorem, with concrete examples.

\medskip

\begin{enumerate}
\item \textit{To evaluate and/or simplify complicated surface integrals}.

\smallskip

\begin{example}
Suppose that $\mathbf{F} = (2x + 3e^y+4e^{z^2}) \mathbf{i} + (x-e^z) \mathbf{j} + (7\cos(y) + 2z) \mathbf{k}$. Let $\mathcal{S}$ be the surface of the circular cylinder $x^2 + y^2 \leq 4$, $0 \leq z \leq 3$,  with top and bottom included. Evaluate $\oiint_{\mathcal{S}} \mathbf{F} \cdot d \mathbf{S} $.
\end{example}

\begin{figure}[h]
\begin{minipage}{\linewidth}
\centering
\includegraphics[width = .5\linewidth]{figures/43fig1.png}
\end{minipage}
\end{figure}

Notice that, while $\mathbf{F}$ is rather complicated, its divergence is simple:
$$
\divg \mathbf{F} = 2 + 0 + 2 = 4,
$$
a constant function over the region $D$ enclosed by $\mathcal{S}$. In particular, the Divergence Theorem tells us that
$$
\oiint_{\mathcal{S}} \mathbf{F} \cdot d \mathbf{\mathcal{S}} = \iiint_{D} 4 \, d V = 4 \cdot \big(\textrm{Volume of } D \big) = 4 \cdot 12 \pi = 48 \pi.
$$

Of course, we can also try a field where $\divg \mathbf{F}$ is not constant on $D$; for example, take
$$
\mathbf{G} = (x^2+\cos y) \mathbf{i} + (z^2-\sin x) \mathbf{k} \Rightarrow \divg \mathbf{G} = 2x + 2z,
$$
with the same $\mathcal{S}$. Again, applying the Divergence Theorem simplifies the problem, since
$$
\oiint_{\mathcal{S}} \mathbf{G} \cdot d \mathbf{S} = \iiint_{D} (2x + 2z) \, d V = \iiint_{D} x \, dV + \iiint_{D} z \, dV.
$$
By the radial symmetry of the cylinder, the first integral involving $x$ is necessarily zero---you can check this by using polar coordinates, if you are hesitant. For the second integral, we use a trick involving averages to write
\begin{eqnarray*}
\iiint_{D} 2 z \, dV & = & 2 \cdot \big(\textrm{Volume of } D \big) \cdot \bigg( \frac{1}{(\textrm{Volume of } D)} \iiint_{D} z \, dV \bigg) \\
\quad & = & 2 \cdot \big(\textrm{Volume of } D \big) \cdot \bar{z},
\end{eqnarray*}
where $\bar{z}$ denotes the average value of $z$ over $D$.  Since $0 \leq z \leq 3$, we know that $\bar{z} = \frac{3}{2}$.  So,
$$
\oiint_{\mathcal{S}} \mathbf{F} \cdot d \mathbf{S} = 2 \cdot \frac{3}{2} \cdot 12 \pi = 36 \pi.
$$


This shows that a seemingly complicated surface integral can, in certain cases, be reduced to an easier integral over a region.  This method is generally useful when: (A) the region satisfies the hypothesis of the Divergence Theorem; and, (B) the divergence of $\mathbf{F}$ is much simpler (as a function) than $\mathbf{F}$ itself.

\medskip

\item \textit{To simplify and/or evaluate volume integrals (less common)}.

\smallskip
\begin{example}
Suppose that $\mathcal{S} \subset \mathbb{R}^3$ is a cone whose base has area $A > 0$ and whose height is $h > 0$ (that is, the base may have arbitrary shape, but we know the height and the base area).  Prove that the volume of the cone (regardless of the base shape) is
\begin{equation}\label{43eq:volumeofcone}
V = \frac{h \cdot A}{3}.
\end{equation}
\end{example}


To show this, let us assume that the vertex of the cone is the origin, and the base is contained in the plane $z = h$ as in the picture. We then let $D \subset \mathbb{R}^3$ denote the region interior to $\mathcal{S}$.

\begin{figure}[h]
\begin{minipage}{\linewidth}
\centering
\includegraphics[width = .5\linewidth]{figures/43fig2.png}
\end{minipage}
\end{figure}


To determine the volume of $D$, the trick is to apply the Divergence Theorem to a good choice of $\mathbf{F}$.  It turns out that $\mathbf{F} = \frac{1}{3}(x \mathbf{i} + y \mathbf{j} + z \mathbf{k})$ ends up working for us.  On one hand, its divergence is constant and equal to 1, so that 
$$
\iiint_{D} \divg \mathbf{F} \, dV = \iiint_{D} 1 \, d V =  \textrm{Volume of } D .
$$
Together with the Divergence Theorem, this implies that
$$
\textrm{Volume of } D = \oiint_{\mathcal{S}} \mathbf{F} \cdot \mathbf{N} \, d S.
$$

On the other hand, we also want the surface integral on the right to be easy to evaluate. Notice that $\mathcal{S} = \mathcal{S}_1 + \mathcal{S}_2$, where $\mathcal{S}_1$ is the base of the cone and $\mathcal{S}_2$ is the rest of $\mathcal{S}$ without the base.  On both $\mathcal{S}_1$ and $\mathcal{S}_2$, we assume that $\mathbf{N}$ points outward from $D$, the region inside the cone.
Here, our choice of $\mathbf{F}$ is also helpful, because:
\begin{itemize}
\item If $(x,y,z) \in \mathcal{S}_1$, then
$$
\mathbf{F} \cdot \mathbf{N} = \frac{1}{3} (x \mathbf{i} + y \mathbf{j} + z \mathbf{k}) \cdot \mathbf{k} = \frac{z}{3}.
$$
But $\mathcal{S}_1$ is contained in the plane $z = h$! So, on $\mathcal{S}_1$, we know that $\mathbf{F} \cdot \mathbf{N} = h/3$. 

\smallskip

\item At points $(x,y,z) \in \mathcal{S}_2$, the field $\mathbf{F}$ is parallel to the surface.  Hence, $\mathbf{F} \cdot \mathbf{N} = 0$ everywhere on $\mathcal{S}_2$ (since $\mathbf{N}$ is perpendicular to $\mathcal{S}_2$ at every point). 
Therefore
$$
\oiint_{\mathcal{S}} \mathbf{F} \cdot \mathbf{N} = \oiint_{\mathcal{S}_1} \mathbf{F} \cdot \mathbf{N} \, d S.
$$
\end{itemize}


Putting this together, we have
$$
\textrm{Volume of } D = \iint_{\mathcal{S}_1} \frac{h}{3} \, dS = \frac{h \cdot A}{3}.
$$


Notice that, in this example, we were very lucky that our conical surface $\mathcal{S} = \mathcal{S}_1 + \mathcal{S}_2$ admitted a vector field $\mathbf{F}$ such that $\mathbf{F} \cdot \mathbf{N}$ was both constant on $\mathcal{S}_1$ and zero on $\mathcal{S}_2$.  This is what made the transition from the integral over a general region to the integral over a conical surface a useful endeavour.  Otherwise, there is no guarantee that moving from a region to a surface integral would simplify our problem!

\medskip

\item \textit{Simplifying Integrals on Surfaces that Are Not Closed}.  The Divergence Theorem, as it stands, is only applicable to \textit{closed} surfaces. However, if the surface is not closed, we can try to ``close" it by adding more pieces. Then the Divergence Theorem can be applied to the closed surface, and we can still benefit from the simplifications as long as the integrals on the added pieces are easier to evaluate than the original one. This is what we do in the next example.

\begin{example}
Evaluate $\iint_{\mathcal S} {\bf F}\cdot d{\bf S}$, if ${\bf F}=(xz+e^y)\ii + (x^5y-z)\jj +(x+1)\kk $ and $\mathcal{S}$ is the part of the sphere $x^2+y^2+z^2=1$ that lies above the plane $z=0$, oriented so that the normal vector points away from the origin.


\end{example}

Let $R$ be the top half of the ball $x^2+y^2+z^2\leq 1$, and $D$ be the disc $x^2+y^2\leq 1$ in the $xy$-plane. If we  let $\mathcal{S}_1$ be the disc $D$ oriented so that the normal vector is $-\kk$, then $\mathcal{S}$ together with $\mathcal{S}_1$ form the oriented boundary of $R$. Applying the
Divergence Theorem, we get
$$
\iiint_R \nabla\cdot{\bf F}\, dV=\iint_{\mathcal S} {\bf F}\cdot d{\bf S}+\iint_D {\bf F}\cdot(-\kk) dA.
$$
We have $\nabla\cdot{\bf F}=z+x^5 $, so that by symmetry and then spherical coordinates
\begin{align*}
\iiint_R \nabla\cdot{\bf F}& =\iiint_D (z+x^5)dV =\iiint_D zdV 
\\
&= \int_0^{2\pi} d\theta \int_0^{\pi/2} d\phi \int_0^1 R\cos\phi\cdot R^2\sin\phi dR
\\
&= 2\pi \int_0^2 R^3 dR \, \int_0^{\pi/2} \sin\phi\cos\phi d\phi
\\
&= 2\pi \cdot \frac{R^4}{4}\Big|_0^1 \cdot \frac{\sin^2\phi}{2}\Big|_0^{\pi/2}=2\pi\cdot\frac{1}{4}\cdot{1}{2}=\frac{\pi}{4}.
\end{align*}
Also,
$$\iint_D {\bf F}\cdot(-\kk)= \iint_D (x-1)dA =-\pi,
$$
where we used that $\iint_D xdA=0$ by symmetry. Hence
$$
\iint_{\mathcal S} {\bf F}\cdot d{\bf S}= \frac{\pi}{4}-(-\pi)=\frac{5\pi}{4}.
$$









\bigskip

\item \textit{Incompressible fields}.  Suppose that $\mathcal{S}$ is a closed, piecewise smooth surface bounding a domain $D \subset \mathbb{R}^3$. Further suppose that $\divg \mathbf{F} = 0$ \textit{at every single point} $P \in D$.  Then,  the Divergence Theorem tells us that
$$
\oiint_{\mathcal{S}} \mathbf{F} \cdot d \mathbf{S} = \iiint_{D} \divg \mathbf{F} d V = 0.
$$
However, it is important that the divergence of $\mathbf{F}$ vanish at every point of $P \in D$. Failure at even a single point can cause the above equality to fail.  The following example demonstrates this phenomenon.

\begin{example}
Let $\mathbf{F} (\mathbf{r})= \frac{c \mathbf{r}}{\vert \mathbf{r} \vert^3}$ in $\mathbb{R}^3$ for some $c\neq 0$ (e.g. a gravitational field).  We proved in Section \ref{subsec:divCurlExamples} that $\mathbf{F}$ is incompressible for all $\mathbf{r} \in \mathbb{R}^3 \setminus \{ \mathbf{0}\}$.

Take two surfaces $\mathcal{S}_1$ and $\mathcal{S}_2$ that are closed, piecewise smooth, and bound domains $D_1, D_2 \subset \mathbb{R}^2$; we can assume that both $D_1$ and $D_2$ contain their boundaries as well.  Assume further that $D_1$ contains the origin and $D_2$ does not.  In the figure below, the vectors illustrate $\mathbf{F}$ and both $D_1$ and $D_2$ are balls.

\begin{figure}[h]
\begin{minipage}{\linewidth}
\centering
\includegraphics[width = .75\linewidth]{figures/43fig3.png}
\end{minipage}
\end{figure}

Then:

\medskip

\begin{itemize}
\item Since $\mathbf{0} \not \in D_2$,  we know that $\divg \mathbf{F} = 0$ everywhere on $D_2$, so that
$$
\oiint_{\mathcal{S}_2} \mathbf{F} \cdot d \mathbf{S} = \iiint_{D} \divg \mathbf{F} d V = 0.
$$
This is generally true for any smooth, closed surface $\mathcal{S}$ whose interior region $D$ does not contain the origin.

\smallskip

\item Now, let us assume that $\mathcal{S}_1$ is the sphere $x^2 + y^2 + z^2 = a^2$ and $\mathbf{N}$ points outward.  Notice that, not only does $\divg \mathbf{F}$ fail to be zero at the origin; in fact, $\mathbf{F}$ has a singularity here. (By singularity, we mean that $\vert \mathbf{F} (\mathbf{r}) \vert \rightarrow \infty$ as $ \mathbf{r}$ approaches the origin.)  Instead, we calculate the surface integral directly:
\begin{eqnarray*}
\oiint_{\mathcal{S}_1} \mathbf{F} \cdot \mathbf{N} dS & = & \oiint_{\mathcal{S}_1} \frac{c \mathbf{r}}{\vert \mathbf{r} \vert^3} \cdot \frac{\mathbf{r}}{\vert \mathbf{r} \vert} d S = \oiint_{\mathcal{S}_1} \frac{c}{a^2} d S,
\end{eqnarray*}
using that $\vert \mathbf{r} \vert = a^2$ on the sphere $\mathcal{S}_1$. Therefore
\begin{eqnarray*}
\oiint_{\mathcal{S}_1} \mathbf{F} \cdot \mathbf{N} dS & = &  \frac{c}{a^2} \cdot \big(\textrm{area of } \mathcal{S}_1 \big) = 4 \pi c.
\end{eqnarray*}
\end{itemize}
\end{example}

Importantly: when $0 \in D_1$ and $\mathcal{S}_1$ is a sphere, we see that the value of the surface integral of $\mathbf{F}$ over $\mathcal{S}_1$ does not depend on the radius $a$! Using the Divergence Theorem, we can show that this also continues to hold for \textit{any closed, smooth surface} enclosing the origin. One such example is drawn below.

\begin{figure}[h]
\begin{minipage}{\linewidth}
\centering
\includegraphics[width = .45\linewidth]{figures/43fig4.pdf}
\end{minipage}
\end{figure}


In terms of the $\delta_0$ function introduced in the last lecture, this shows that
$$
\divg \mathbf{F} = 4 \pi c \delta_0, \textrm{ whenever } \mathbf{F}(\mathbf{r}) = \frac{c \, \mathbf{r}}{\vert \mathbf{r} \vert^3}.
$$
\end{enumerate}






\subsection{A Sketch of the Proof of Theorem \ref{43thm:divergence}}
The main steps of the proof are similar to those for Green's Theorem.
We start with two reductions.

\begin{enumerate}[1.]
\item First, we reduce to the case of regions that are $x$-simple, $y$-simple, and $z$-simple. This reduction is similar to the proof of Green's Theorem. In many cases, it suffices to cut it up the region into finitely many pieces, prove the theorem for each of the domain-surface pairs, then add up integrals on both sides. The cutting process creates extra boundary surfaces (i.e. surfaces which are not contained in the original surface); however, the integrals on these extra surfaces will cancel out, since each surface will be counted twice with opposite orientations.  This is one reason we \textit{must} choose $\mathbf{N}$ to point outward on each component! In the general case, we may also need an additional limiting argument.

This step is presented here without proof. The remaining steps in the proof will be completely rigorous.

\smallskip

\item Now, suppose we are on one of these domain-surface pairs. The next step is to break the vector field $\mathbf{F}$ into its component pieces $F_1, F_2$, and $F_3$. We may then evaluate and compare the surface and volume integrals for each component, rather than tackling the integral of $\mathbf{F}$ all at once.
\end{enumerate}

Having performed these reductions, it suffices to prove the following (much simpler) version of the Divergence Theorem.

\begin{theorem}\label{43lemma1} (A special case of the Divergence Theorem)
Suppose that $D \subset \mathbb{R}^3$ is the region given by
$$
D = \{(x,y,z) : \ (x,y) \in R,\    f(x,y) \leq z \leq g(x,y) \},
$$
where $R \subset \mathbb{R}^2$ is a 2-dimensional domain. Let $\mathbf{F} =  F_3 \mathbf{k}$, and assume that $f,g,F_3$ are $C^1$. Then 
\begin{equation}\label{43eq:simplifieddivergence}
\iiint_{D} \frac{\partial F_3}{\partial z} d V = \oiint_{\mathcal{S}} F_3 \mathbf{k} \cdot \mathbf{N} \, dS,
\end{equation}
where $\mathcal{S}$ is the boundary surface of $D$.

\smallskip
Below is a small portrait of the geometric situation described:
\begin{figure}[h]
\begin{minipage}{\linewidth}
\centering
\includegraphics[width = .5\linewidth]{figures/43fig6.pdf}
\end{minipage}
\end{figure}
\end{theorem}

\begin{proof}[Proof of Theorem \ref{43lemma1}]
The main idea (as in the proof of Green's Theorem!) is to apply the Fundamental Theorem of Calculus in the $z$-direction. We first have to do some work before getting to the point where we can do that.
We start with the surface integral in (\ref{43eq:simplifieddivergence}):
\begin{eqnarray*}
\oiint_{\mathcal{S}} F_3 \mathbf{k} \cdot \mathbf{N} \, dS = \iint_{\mathcal{S}_1} F_3 \mathbf{k} \cdot \mathbf{N} \, dS +
\iint_{\mathcal{S}_2} F_3 \mathbf{k} \cdot \mathbf{N} \, dS +
\iint_{\mathcal{S}_3} F_3 \mathbf{k} \cdot \mathbf{N} \, dS.
\end{eqnarray*}
where $\mathcal{S}_1$ and $\mathcal{S}_2$ are the top and bottom surfaces given by the equations $z = g(x,y)$ and $z = f(x,y)$ (resp.) and $\mathcal{S}_3$ is the surface in-between.  On the surface in-between (see the above drawing), we have
$$
\iint_{\mathcal{S}_3} F_3 \mathbf{k} \cdot \mathbf{N} \, dS = 0,
$$
since $\mathbf{N} \perp \mathbf{k}$ along the sides of $\mathbf{S}_3$. We are left with the top and bottom surfaces.
\begin{itemize}
\item For the top surface $\mathcal{S}_1$, let $\mathbf{r} = (x,y, g(x,y))$ so that $d \mathbf{S} = (-g_x \mathbf{i} - g_y \mathbf{j} + \mathbf{k})dA$. Then,
$$
\iint_{\mathcal{S}_1} F_3 \mathbf{k} \cdot \mathbf{N} \, dS = \iint_{R} F_3 (x,y,g(x,y)) \, dx dy.
$$

\smallskip
\item For the bottom surface $\mathcal{S}_2$, a similar calculation gives
$$
\iint_{\mathcal{S}_2} F_3 \mathbf{k} \cdot \mathbf{N} \, dS = - \iint_{R} F_3 (x,y,f(x,y)) dx dy,
$$
and the minus sign is due to $\mathbf{N}$ pointing \textit{downward} on the bottom surface.
\end{itemize}


Adding up and then applying the Fundamental Theorem of Calculus in the $z$ variable, we get
\begin{equation*}
\begin{split}
\oiint_{\mathcal{S}} F_3 \mathbf{k} \cdot \mathbf{N} \, dS
&= 
 \iint_{R} \bigg[F_3 (x,y,g(x,y)) - F_3 (x,y,f(x,y)) \bigg] dx dy
 \\
 &=  \iint_{R} \bigg[\int_{f(x,y)}^{g(x,y)} \frac{\partial F_3}{\partial z}dz\bigg] dx dy \\
&= 
\iiint_{D} \frac{\partial F_3}{\partial z} \, dV,
\end{split}
\end{equation*}
as claimed in (\ref{43eq:simplifieddivergence}).
\end{proof}

\section*{Practice Problems}
\begin{enumerate}[1.]




\item
Compute the flux of the vector field ${\bf F}= x{\bf i}+y{\bf j} -x\kk $
out of a closed surface consisting of the part of the cylinder $x^2+y^2=4$ between the planes $z=0$ and $z=3$, together with the discs at the top and bottom, with the normal vector pointing outward.

\bigskip



\item
{Evaluate $\iint_{\mathcal S} {\bf F}\cdot d{\bf S}$, if ${\bf F}=(e^{y^2}-x^3){\bf i}+(y^2+e^{2z^2}){\bf j}
+e^{x^2}{\bf k}$ and $\mathcal{S}$ is the sphere $x^2+y^2+z^2=1$, oriented so that the normal vector points outward.}

\bigskip




\item Evaluate
$\iint_{\mathcal S} {\bf F}\cdot d{\bf S}$, if ${\bf F}=(x^2+y^2){\bf i}+z^2{\bf j}
+ {\bf k}$ and $\mathcal{S}$ is the half-sphere $x^2+y^2+z^2=1$, $z\geq 0$, oriented so that the normal vector points away from the origin.
(Hint: complete the sphere to a closed surface, then apply the Divergence Theorem.)


 \bigskip
 
 

\item
{Evaluate the integral
$\iint_{\mathcal S} {\bf F}\cdot d{\bf S}$, if ${\bf F}=y^2\sin y \cos z {\bf i}+x^2\cos x \sin z {\bf j}
+ (z^2+1) {\bf k}$ and $\mathcal{S}$ is the surface consisting of the cylinder $x^2+y^2=1$, $0\leq z\leq 2$, together with the disc at the top, oriented so that the normal vector points away from the origin.}




\bigskip

\item
{Suppose that $g(x,y,z)$ is a smooth function on all of $\rr^3$, that the
level surface 
$\mathcal{S}=\{(x,y,z):\ g(x,y,z)=0\}$ is closed, and that
$\nabla g \neq 0$ on $\mathcal{S}$.


\smallskip


(a)
Prove that there is a point where the vector field
${\bf F}=\nabla g$ has nonzero divergence.}

\smallskip

{(b) Does there have to exist a point where ${\bf F}=\nabla g$ has positive divergence?
If yes, explain why. If no, give a counterexample.}

\bigskip

\item 
{Assume that a solid $D$ in $\rr^3$ and its boundary $\mathcal{S}$ satisfy the assumptions
of the Divergence Theorem.  Let $f,g:\rr^3\to\rr$ be $C^2$ functions.
Prove that
$$\iint_\mathcal{S}(f\nabla g-g\nabla f)\cdot d{\bf S}
=\iiint_D(f\nabla^2 g-g\nabla^2 f)dV.$$
Here $\nabla^2 f=\nabla\cdot(\nabla f)=f_{xx}+f_{yy}+f_{zz}$.}

\bigskip

 

\item {Let ${\bf F}$ be an incompressible smooth vector field such that its field lines are the hyperbolas
$$
x^2+y^2=c(z^2+1),\ ax+by=0,
$$
for $c\geq 0$ and $a,b\in\rr$, all oriented towards increasing $z$. (For $c=0$, this is the $z$-axis.)  
Suppose that 
$$
\iint_{D_A} {\bf F}\cdot \kk \,dS = \ln(A+1)
$$
for all $A\geq 0$, where $D_A=\{(x,y,0):\ x^2+y^2\leq A^2\}$.

What is $\iint_{\mathcal{S}} {\bf F}\cdot d{\bf S}$, if $\mathcal{S}$ is the disc $\{(x,y,4):\ x^2+y^2\leq 9\}$ with the normal vector pointing up? Justify your answer.}









\end{enumerate}



