Line Integrals

This notebook describes how to compute and visualize line integrals in Mathematica.  In particular, you'll see how to:
- Compute the line integral of a function of several variables:   \(TraditionalForm
      \`∫\_C\%□\( f(x, y, z)\) ds\).
- Compute the line integral along a path through a vector field (work integral:  \(TraditionalForm
      \`∫\_C\%□ F . dR\)).
- Visualize a path through a vector field.

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: line_integrals.nb

Compute Line Integral of a Function of Several Variables:   \(TraditionalForm
      \`∫\_C\%□\( f(x, y, z)\) ds\)

The code below is designed to compute a line integral along a path, defined by <x(t),y(t),z(t)>, accumulating the values of the function, f(x,y,z), along the path:  \(TraditionalForm
      \`∫\_C\%□\( f(x, y, z)\) ds\).  In 2D, this is sometimes refered to as the "shower curtain" integral where the function f(x,y) gives the height of the "curtain" and the path gives its trace through the xy-plane.  Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2..4 - Define the x, y, z components of the path.
Line 5 - Defines the differential arc length.
Line 6 - Gives the function f(x,y,z) in terms of the underlying parameter t.
Line 7 - Puts the pieces together into an integral and evaluates it.

Clear[f, x, y, z, t, ds]\(x[t_] := t; 
y[t_] := t; 
z[t_] := t^2; 

    ds[t_] := 
      Sqrt[\((\(x'\)[t])\)^2 + \((\(y'\)[t])\)^2 + \((\(z'\)[t])\)^2]; 

    f[t_] := x[t] + y[t] + z[t]; 

    ∫\_0\%2 f[t]*ds[t] \[DifferentialD]t
\)

Compute the Line Integral along a Path through a Vector Field (Work Integral:  \(TraditionalForm
      \`∫\_C\%□ F . dR\))

The code below is designed to computer a line integral along a path, defined by R(t)=<x(t),y(t),z(t)>, through a vector field, accumulating the dot products of the tangent vectors with the field vectors along the path:  \(TraditionalForm
      \`∫\_C\%□ F . dR\).  When the vector field represents a force field, this integral computes the work done by the field as a particle moves down the path.   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2..4 - Define the x, y, z components of the path.
Line 5 - Defines the path, R(t), using the just defined components.
Line 6 - Defines the vector field, F(x,y,z), in terms of the underlying parameter t.
Line 7 - Puts the pieces together into an integral and evaluates it.

Clear[F, x, y, z, t, R]\(x[t_] := t; 
y[t_] := \(-t^2\); 
z[t_] := 1; 

    R[t_] := {x[t], y[t], z[t]}; 

    F[t_] := {Cos[x[t]], \(-y[t]\), x[t]*z[t]}; 

    ∫\_0\%3 F[t] . \(R'\)[t] \[DifferentialD]t
\)

Visualize a Path through a Vector Field

Sometimes it helps to visualize the path in the vector field.  Below is code to accomplish this both in 2D and 3D.  First the 2D example.  Here's how the code goes:
Line 1 - Clears any previous definitions of the symbols used.
Line 2 - Loads the Graphics`PlotField` package which is needed to plot the vector field.
Line 3..5 - Defines the path, R(t), in this case a full ellipse.
Line 6 - Generates the plot of the path R(t).
Line 7 - Generates the plot of the vector field.
Line 8 - Shows the path and the vector field on the same graph.

Clear[F, x, y, t, R]Needs["Graphics`PlotField`"]\(x[t_] := 2  Cos[t]; 
y[t_] := 3  Sin[t]; 
R[t_] := {x[t], y[t]}; 

    path = ParametricPlot[R[t], {t, 0, 2  π}, Compiled -> False]; 

    field = PlotVectorField[{Cos[x], \(-y\)*x}, {x, \(-3\), 3}, 

        		{y, \(-3\), 3}]; 
Show[path, field]\)

Now for a 3D example.  Here's how the code goes:
Line 1 - Clears any previous definitions of the symbols used.
Line 2 - Loads the Graphics`PlotField3D` package which is needed to plot the vector field.
Line 3..6 - Defines the path, R(t), in this case a full ellipse.
Line 7 - Generates the plot of the path R(t).
Line 8 - Generates the plot of the vector field.
Line 9 - Shows the path and the vector field on the same graph.

Clear[F, x, y, z, t, R]Needs["Graphics`PlotField3D`"]\(x[t_] := t; 
y[t_] := \(-t^2\); 
z[t_] := 1; 

    R[t_] := {x[t], y[t], z[t]}; 
path = ParametricPlot3D[R[t], {t, 0, 3}]; 
    
field = 
      PlotVectorField3D[{Cos[x], \(-y\), x*z}, {x, 0, 3}, 

        		{y, \(-8\), 0}, {z, 0, 2}]; 
Show[path, field]\)