Divergence Theorem of Gauss

This notebook describes how to compute 3D flux integrals using the Divergence theorem of Gauss to change the surface integral into a triple integral of divergence and Mathematica to perform the computations.  In particular, you'll see how to:
- Handle constant divergence without integration.
- Compute the triple divergence integral in Cartesian coordinates.

The functions in this notebook are set up to be easily cut-and-pasted so you can easily experiment with them.

TO SEE WHAT THIS NOTEBOOK PROVIDES:
- Select Kernel|Evaluation|Evaluate_Notebook to execute all the cell and produce the graphics.
- Then scroll through reading the commands and associated comments while you look at the commands' results.
- All input cells are set up such that they can be cut-and-pasted in their entirety for easy "re-use".

The material in this notebook was originally developed by Capt Rob Wolverton and was re-formatted into a tutorial by Lt Col Steve Hadfield, both of the USAF Academy, Dept of Mathematical Sciences.	
Filename: divergence_theorem.nb

Constant Divergence without Integration

When the divergence of the vector field is constant, we can simply multiply the divergence by the volume of the region enclosed by the surface.  Here's how the code does it on an example where the vector field is F(x,y,z) = <2x, 3y, -z> and the surface is a sphere of radius 2:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Loads the Calculus`VectorAnalysis` package needed for the Div function.
Line 3 - Defines the vector field.
Line 4 - Computes the divergence expression for the vector field.  In this case, it is a constant (4).  NOTE:  We need to tell Mathematica what coordinate system we are working in (here it is Cartesian).
Line 5..7 - Evaluates the volume of the enclosed 3D region (in this case the volume of a sphere).
Line 8 - Evaluates the flux as divergence times the volume.

Clear[F, x, y, z, DiverF, r, Vol]Needs["Calculus`VectorAnalysis`"]\(F[x_, y_, z_] = {2  x, 3  y, \(-z\)}; 

    DiverF[x_, y_, z_] = Div[F[x, y, z], Cartesian[x, y, z]]
 (*\ 
      Volume\ of\ a\ sphere\ \(4\/3\) π\ r\^3\ *) \)\(r = 2; 
Vol\  = \ 4\/3*π*\ r\^3; 
DiverF[x, y, z]*Vol\)

Compute Triple Divergence Integral in Cartesian Coordinates

The flux integral over a piecewise smooth closed surface in three space can be computed via a triple integral of the field's divergence over the enclosed volume.  To accomplish this triple divergence integral when using Cartesian coordinates you can use the example code below where the field is F(x,y,z) = <x-y, y-4xz, xz> and the surface is the rectangular box enclosing [0,4]X[0,2]X[0,3].  Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Loads the Calculus`VectorAnalysis` package needed for the Div function.
Line 3 - Defines the vector field.
Line 4 - Computes the divergence expression for the vector field.  In this case, it is a constant (4).  NOTE:  We need to tell Mathematica what coordinate system we are working in (here it is Cartesian).
Line 5 - Evaluates the triple divergence integral.
NOTE:  Sometimes the actual integration is easier to accomplish in another coordinate system (cylindrical or spherical) due to the nature of the region.  In such cases, it can be helpful to have Mathematica compute the integrand (using "DiverF[x,y,z]") and then you can easily convert this integrand to the new coordinate system and set up the limits of integration accordingly.

Clear[F, x, y, z, DiverF]Needs["Calculus`VectorAnalysis`"]\(F[x_, y_, z_] = {x - y, y - 4*x*z, x*z}; 

    DiverF[x_, y_, z_] = Div[F[x, y, z], Cartesian[x, y, z]]; 

    ∫\_0\%4
        \(∫\_0\%2
          \(∫\_0\%3 DiverF[x, y, z] \[DifferentialD]z 
            \[DifferentialD]y \[DifferentialD]x\)\)\)