Conservative Fields, Potential Functions, Independence of Path

This notebook describes how to work with conservative vector fields in Mathematica.  In particular, this notebook contains examples of how to:
- Test if a 2D vector field is conservative.
- Compute the potential function for a 2D conservative vector field.
- Evaluate a line integral in a 2D conservative vector field using the Fundamental Theorem of Line Integrals.
- Test if a 3D vector field is conservative.
- Compute the potential function for a 3D conservative vector field.
- Evaluate a line integral in a 3D conservative vector field using the Fundamental Theorem of Line Integrals.

The function in this notebook is 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: indep_of_path.nb

Test for a Conservative 2D Vector Field

The code below tests if a 2D vector field, F=<f,g> is conservative by computing and comparing the values ((∂_x) g = (∂_y) f).   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Defines the vector field.
Line 3 - Calculates (∂_y) f using D[F[x,y][[1]],y] (F[x,y][[1]] extracts the first component of the vector field, that is, f of F=<f,g>) and (∂_x) g using D[F[x,y][[2]],x] (F[x,y][[2]] extracts the second component).  These quantities are compared and if equal the message "conservative" is printed, otherwise "nonconservative" is printed.

Clear[F, x, y]\(F[x_, y_] = {6*y + y*E\^\(x*y\), 6*x + x*E\^\(x*y\)}; 

    If[D[\(F[x, y]\)[\([1]\)], y] == D[\(F[x, y]\)[\([2]\)], x], 
      Conservative, Nonconservative]\)

Find Potential Function for a Conservative 2D Vector Field

The code below does integrates the two components of a conservative vector field so the results may be compared and combined into the corresponding potential function.   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Defines the vector field.
Line 3 - Integrates the first component of the vector field with respect to x.
Line 4 - Integrates the second component of the vector field with respect to y.

Clear[F, x, y, ϕx, ϕy]\(F[x_, y_] = {6*y + y*E^\((x*y)\), 6*x + x*E^\((x*y)\)}; 

    ϕx[x_, y_] = ∫\(F[x, y]\)[\([1]\)] \[DifferentialD]x\)\(ϕy[x_, y_] = ∫\(F[x, y]\)[\([2]\)] \[DifferentialD]y

    \)

Use Independence of Path to Evaluate a Line Integral in 2D

The code below use independence of path and the Fundamental Theorem of Line Integrals to evaluate a line integral in a conservative 2D vector field.   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Defines the vector field.
Line 3 - Integrates the first component of the vector field with respect to x.
Line 4 - Integrates the second component of the vector field with respect to y.
Line 5..6 - Evaluate these two antiderivatives so they can be compared and a potential function can be constructed.
Line 7 - Defines ϕ(x,y) as the resulting potential function.  HINT:  You can do this easily by running lines 1..6 of the code and then cutting-and-pasting the results of Lines 5 & 6 to build the definition for ϕ(x,y).
Line 8 - Computes the line integral from (1,3) to (2,2) using this potential function and the Fundamental Theorem of Line Integrals.

Clear[F, x, y, ϕx, ϕy]\(F[x_, y_] = {6*y + y*E^\((x*y)\) + 1, 6*x + x*E^\((x*y)\)}; 

    ϕx[x_, y_] = ∫\(F[x, y]\)[\([1]\)] \[DifferentialD]x; 

    ϕy[x_, y_] = ∫\(F[x, y]\)[\([2]\)] \[DifferentialD]y; 

    ϕx[x, y]\)ϕy[x, y]ϕ[x_, y_] := (E^(x y)) + x (1 + 6 y)\(ϕ[2, 2] - ϕ[1, 3]
\)

Test for a Conservative 3D Vector Field

The code below tests if a 3D vector field, F=<f,g,h> is conservative by computing the curl(F) and comparing it to the zero vector.   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Loads the Calculus`VectorAnalysis` package which is needed to get the Curl function.
Line 3 - Defines the vector field.
Line 4 - Calculates the Curl(F) and compares it to the zero vector.  If equal the message "conservative" is printed, otherwise "nonconservative" is printed.

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

    If[Curl[F[x, y, z], Cartesian[x, y, z]] == {0, 0, 0}, Conservative, 
      Nonconservative]\)

Find Potential Function for a Conservative 3D Vector Field

The code below does integrates the two components of a conservative vector field so the results may be compared and combined into the corresponding potential function.   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Defines the vector field.
Line 3..5 - Integrate the components of the vector field with respect to corresponding independent variables.
Line 6..8 - Shows the results of these integrals so they can be compared and combined into the potential function (in this case ϕ(x,y,z)=xy+xz+yz).

Clear[F, x, y, z, ϕx, ϕy, ϕz]\(F[x_, y_, z_] = {y + z, x + z, x + y}; 

    ϕx[x_, y_, z_] := 
      ∫\(F[x, y, z]\)[\([1]\)] \[DifferentialD]x; 

    ϕy[x_, y_, z_] := 
      ∫\(F[x, y, z]\)[\([2]\)] \[DifferentialD]y; 

    ϕz[x_, y_, z_] := 
      ∫\(F[x, y, z]\)[\([3]\)] \[DifferentialD]z; 

    ϕx[x, y, z]\)ϕy[x, y, z]ϕz[x, y, z]

Use Independence of Path to Evaluate a Line Integral in 3D

The code below use independence of path and the Fundamental Theorem of Line Integrals to evaluate a line integral in a conservative 3D vector field.   Here's how the code does it:
Line 1 - Clears any previous symbol definitions to avoid conflicts.
Line 2 - Defines the vector field.
Line 3..5 - Integrates the components of the vector field with respect to independent variables.
Line 6..8 - Evaluates these integrals so they can be compared and combined into the potential function.
Line 9 - Defines ϕ(x,y,z) as the resulting potential function.  HINT:  You can do this easily by running lines 1..8 of the code and then cutting-and-pasting the results of Lines 6..8 to build the definition for ϕ(x,y,z).
Line 10 - Computes the line integral from (π,1,3) to (2,2,-1) using this potential function and the Fundamental Theorem of Line Integrals.

Clear[F, x, y, z, ϕx, ϕy, ϕz, ϕ]\(F[x_, y_, z_] = {y + z, x + z, x + y}; 

    ϕx[x_, y_, z_] := 
      ∫\(F[x, y, z]\)[\([1]\)] \[DifferentialD]x; 

    ϕy[x_, y_, z_] := 
      ∫\(F[x, y, z]\)[\([2]\)] \[DifferentialD]y; 

    ϕz[x_, y_, z_] := 
      ∫\(F[x, y, z]\)[\([3]\)] \[DifferentialD]z; 

    ϕx[x, y, z]\)ϕy[x, y, z]ϕz[x, y, z]ϕ[x_, y_, z_] := x*y + x*z + y*z\(ϕ[2, 2, \(-1\)] - ϕ[π, 1, 3]
\)