Divergence and Curl and Their Geometric Interpretations

Setting up the combined potential due to three point potentials as an example to visualize gradients, divergences, and curls

Simple ( 2 D ) 1 r potential : ( gravity , electrostatic potential have this dependency )

In[48]:=

potential [ x_ , y_ , xo_ , yo_ ] := - 1 / Sqrt [ ( x - xo ) ^ 2 + ( y - yo ) ^ 2 ]

A field source located a distance 1 south of the origin

In[49]:=

HoleSouth [ x_ , y_ ] := potential [ x , y , Cos [ 3 Pi / 2 ] , Sin [ 3 Pi / 2 ] ]

Sources located distance 1 at 30° and 150°:

In[50]:=

HoleNorthWest [ x_ , y_ ] := potential [ x , y , Cos [ Pi / 6 ] , Sin [ Pi / 6 ] ]

In[51]:=

HoleNorthEast [ x_ , y_ ] := potential [ x , y , Cos [ 5 Pi / 6 ] , Sin [ 5 Pi / 6 ] ]

Function that returns the two dimensional (x,y) gradient field of any function declared a function of two arguments:

In[52]:=

gradfield [ scalarfunction_ ] := { D [ scalarfunction [ x , y ] , x ] // Simplify , D [ scalarfunction [ x , y ] , y ] // Simplify }

Generalizing the function to any arguments:

In[53]:=

gradfield [ scalarfunction_ , x_ , y_ ] := { D [ scalarfunction [ x , y ] , x ] // Simplify , D [ scalarfunction [ x , y ] , y ] // Simplify }

The sum of three potentials:

In[54]:=

ThreeHolePotential [ x_ , y_ ] := HoleSouth [ x , y ] + HoleNorthWest [ x , y ] + HoleNorthEast [ x , y ]

f(x,y) visualization of the scalar potential:

In[55]:=

Plot3D [ ThreeHolePotential [ x , y ] , { x , - 2 , 2 } , { y , - 2 , 2 } ]

[Graphics:HTMLFiles/Lecture-13_1.gif]

Out[55]=

SurfaceGraphics

Contour visualization of the three-hole potential

In[56]:=

ContourPlot [ ThreeHolePotential [ x , y ] , { x , - 2 , 2 } , { y , - 2 , 2 } , PlotPoints 40 , ColorFunction ( Hue [ 1 - # * 0.66 ] & ) ]

[Graphics:HTMLFiles/Lecture-13_2.gif]

Out[56]=

ContourGraphics

Gradient field of three-hole potential

In[57]:=

gradthreehole = gradfield [ ThreeHolePotential ]

Out[57]=

{ - 3 2 + x ( 1 - 3 x + x 2 - y + y 2 ) 3 / 2 + 3 2 + x ( 1 + 3 x + x 2 - y + y 2 ) 3 / 2 + x ( x 2 + ( 1 + y ) 2 ) 3 / 2 , - 1 2 + y ( 1 - 3 x + x 2 - y + y 2 ) 3 / 2 + - 1 2 + y ( 1 + 3 x + x 2 - y + y 2 ) 3 / 2 + 1 + y ( x 2 + ( 1 + y ) 2 ) 3 / 2 }

In[58]:=

<< Graphics`PlotField`

In[59]:=

PlotVectorField [ gradthreehole , { x , - 2 , 2 } , { y , - 2 , 2 } , ScaleFactor 0.2 , ColorFunction ( Hue [ 1 - # * 0.66 ] & ) , PlotPoints 21 ]

Power :: infy : Infinite expression 1 0 3 / 2 encountered. More… "Infinite expression \\!\\(1\\/0\\^\\(3/2\\)\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Power::infy\\\"]\\)"

:: indet : Indeterminate expression 0 ComplexInfinity encountered. More… "Indeterminate expression \\!\\(0\\\\ ComplexInfinity\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::indet\\\"]\\)"

Power :: infy : Infinite expression 1 0 3 / 2 encountered. More… "Infinite expression \\!\\(1\\/0\\^\\(3/2\\)\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Power::infy\\\"]\\)"

:: indet : Indeterminate expression 0 ComplexInfinity encountered. More… "Indeterminate expression \\!\\(0\\\\ ComplexInfinity\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::indet\\\"]\\)"

[Graphics:HTMLFiles/Lecture-13_3.gif]

Out[59]=

Graphics

Function that takes a two-dimensional vector function of (x,y) as an argument and returns its divergence

In[60]:=

divergence [ { xcomp_ , ycomp_ } ] := Simplify [ D [ xcomp , x ] + D [ ycomp , y ] ]

In[61]:=

divgradthreehole = divergence [ gradfield [ ThreeHolePotential ] ] // Simplify

Out[61]=

- 3 ( 3 - 2 x ) 2 4 ( 1 - 3 x + x 2 - y + y 2 ) 5 / 2 - 3 ( 1 - 2 y ) 2 4 ( 1 - 3 x + x 2 - y + y 2 ) 5 / 2 + 2 ( 1 - 3 x + x 2 - y + y 2 ) 3 / 2 - 3 ( 3 + 2 x ) 2 4 ( 1 + 3 x + x 2 - y + y 2 ) 5 / 2 - 3 ( 1 - 2 y ) 2 4 ( 1 + 3 x + x 2 - y + y 2 ) 5 / 2 + 2 ( 1 + 3 x + x 2 - y + y 2 ) 3 / 2 - 3 x 2 ( x 2 + ( 1 + y ) 2 ) 5 / 2 - 3 ( 1 + y ) 2 ( x 2 + ( 1 + y ) 2 ) 5 / 2 + 2 ( x 2 + ( 1 + y ) 2 ) 3 / 2

Plotting the divergence of the gradient ( · ( f ) is the ``Laplacian '' 2 f , sometimes indicated with symbol Δf )

In[88]:=

Plot3D [ divgradthreehole , { x , - 2 , 2 } , { y , - 2 , 2 } , PlotPoints -> 60 ]

[Graphics:HTMLFiles/Lecture-13_4.gif]

Out[88]=

SurfaceGraphics

It is no surprise that many of these differential operations already exist in Mathematica packages.

Using the Vector Analysis Package

In[1]:=

<< Calculus`VectorAnalysis`

Coordinate Systems

Converting between coordinate systems

The spherical coordinates expressed in terms of the cartesian x,y,z

In[2]:=

CoordinatesFromCartesian [ { x , y , z } , Spherical [ r , theta , phi ] ]

General :: spell1 : Possible spelling error: new symbol name \" theta \" is similar to existing symbol \" Ttheta \". More… "Possible spelling error: new symbol name \\\"\\!\\(theta\\)\\\" is similar to existing symbol \\\"\\!\\(Ttheta\\)\\\". \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::spell1\\\"]\\)"

Out[2]=

{ x 2 + y 2 + z 2 , ArcCos [ z x 2 + y 2 + z 2 ] , ArcTan [ x , y ] }

The cartesian coordinates expressed in terms of the spherical r θ φ

In[3]:=

CoordinatesToCartesian [ { r , theta , phi } , Spherical [ r , theta , phi ] ]

Out[3]=

{ r Cos [ phi ] Sin [ theta ] , r Sin [ phi ] Sin [ theta ] , r Cos [ theta ] }

The equation of a line  through the origin in spherical coodinates

In[4]:=

Simplify [ CoordinatesFromCartesian [ { a t , b t , c t } , Spherical [ r , theta , phi ] ] , t Reals ]

Out[4]=

{ a 2 + b 2 + c 2 Abs [ t ] , ArcCos [ c t a 2 + b 2 + c 2 Abs [ t ] ] , ArcTan [ a t , b t ] }

An example of calculating the positions of cities in cartesian and spherical coordinates.

In[5]:=

<< Miscellaneous`CityData`

Boston is located at latitude 42° 21' 30" N  and longitude -71°,-3',-37" W

In[6]:=

boston = CityData [ Boston , CityPosition ]

Out[6]=

{ { 42 , 21 , 30 } , { - 71 , - 3 , - 37 } }

In[7]:=

paris = CityData [ Paris , CityPosition ]

Out[7]=

{ { 48 , 52 } , { 2 , 20 } }

In[8]:=

SphericalCoordinatesofCity [ cityname_String ] := { 6378.1 , 2 Pi 360 ToDegrees [ CityData [ cityname , CityPosition ] [ [ 1 ] ] ] , 2 Pi 360 ToDegrees [ CityData [ cityname , CityPosition ] [ [ 2 ] ] ] }

In[15]:=

SphericalCoordinatesofCity [ Boston ]

Out[15]=

{ 6378.1 , 5083 π 21600 , - 255817 π 648000 }

In[9]:=

CartesianCoordinatesofCity [ cityname_String ] := CoordinatesToCartesian [ SphericalCoordinatesofCity [ cityname ] , Spherical [ r , theta , phi ] ]

In[10]:=

CartesianCoordinatesofCity [ Paris ]

Out[10]=

{ 4799.879597331717 , 195.5801062763877 , 4195.6005390346245 }

In[11]:=

MinimumTunnel [ city1_String , city2_String ] := Norm [ CartesianCoordinatesofCity [ city1 ] - CartesianCoordinatesofCity [ city2 ] ]

In[12]:=

MinimumTunnel [ Boston , Paris ]

Out[12]=

5478.338566127883

Minimum travel distance between Boston and Paris for a round earth

In[109]:=

SphericalDistance [ boston , paris ] // N

Out[109]=

5529.743203638526

In[110]:=

SpheroidalDistance [ boston , paris ] // N

Out[110]=

5545.034276030287

In[67]:=

SimplePot [ x_ , y_ , z_ , n_ ] := 1 ( x ^ 2 + y ^ 2 + z ^ 2 ) n 2

In[68]:=

Grad [ SimplePot [ x , y , z , 1 ] , Cartesian [ x , y , z ] ]

Out[68]=

{ - x ( x 2 + y 2 + z 2 ) 3 / 2 , - y ( x 2 + y 2 + z 2 ) 3 / 2 , - z ( x 2 + y 2 + z 2 ) 3 / 2 }

The above is equal to r ( || r || ) 3

In[91]:=

GradSimplePot [ x_ , y_ , z_ , n_ ] := Evaluate [ Grad [ SimplePot [ x , y , z , n ] , Cartesian [ x , y , z ] ] ]

In[70]:=

Div [ GradSimplePot [ x , y , z , n ] , Cartesian [ x , y , z ] ] // Simplify

Out[70]=

( - 1 + n ) n ( x 2 + y 2 + z 2 ) - 1 - n 2

The above is equal to n ( n - 1 ) r ( || r || ) 2 + n

In[71]:=

Div [ GradSimplePot [ x , y , z , 1 ] , Cartesian [ x , y , z ] ] // Simplify

Out[71]=

0

This makes ``sense '' because the amount of stuff flowing into a sphere is like the gradient * 4 π r 2 which is independent of the size of the sphere for n = 1

An example of Curl

There is a very useful free software tool for solving minimal surface (and many other) variational problems called Surface Evolver by Ken Brakke.  To use Surface Evolver to greatest possible advantage, a user should be adept at using results from vector analysis.  Mathematica's Vector Analysis package is very helpful aid for developing powerful Evolver codes.  The following example is extracted from the Surface Evolver manual.

In[72]:=

LeavingKansas [ x_ , y_ , z_ , n_ ] := z n ( x ^ 2 + y ^ 2 ) ( x ^ 2 + y ^ 2 + z ^ 2 ) n 2 { y , - x , 0 }

In[73]:=

LeavingKansas [ x , y , z , 3 ]

Out[73]=

{ y z 3 ( x 2 + y 2 ) ( x 2 + y 2 + z 2 ) 3 / 2 , - x z 3 ( x 2 + y 2 ) ( x 2 + y 2 + z 2 ) 3 / 2 , 0 }

In[74]:=

<< Graphics`PlotField3D`

Visualize the vector field for n=3, note that the function will be singular near the z-axis

In[75]:=

PlotVectorField3D [ LeavingKansas [ x , y , z , 3 ] , { x , - 1 , 1 } , { y , - 1 , 1 } , { z , - .5 , .5 } , VectorHeads True , ColorFunction ( ( Hue [ # * .66 ] ) & ) , PlotPoints 15 , ScaleFactor 0.5 ]

Power :: infy : Infinite expression 1 0 encountered. More… "Infinite expression \\!\\(1\\/0\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Power::infy\\\"]\\)"

:: indet : Indeterminate expression 0 ComplexInfinity encountered. More… "Indeterminate expression \\!\\(0\\\\ ComplexInfinity\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::indet\\\"]\\)"

:: indet : Indeterminate expression 0 ComplexInfinity encountered. More… "Indeterminate expression \\!\\(0\\\\ ComplexInfinity\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::indet\\\"]\\)"

:: indet : Indeterminate expression 0 ComplexInfinity encountered. More… "Indeterminate expression \\!\\(0\\\\ ComplexInfinity\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::indet\\\"]\\)"

General :: stop : Further output of :: indet will be suppressed during this calculation. More… "Further output of \\!\\(\[Infinity] :: \\\"indet\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

Power :: infy : Infinite expression 1 0 encountered. More… "Infinite expression \\!\\(1\\/0\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Power::infy\\\"]\\)"

Power :: infy : Infinite expression 1 0 encountered. More… "Infinite expression \\!\\(1\\/0\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Power::infy\\\"]\\)"

General :: stop : Further output of Power :: infy will be suppressed during this calculation. More… "Further output of \\!\\(Power :: \\\"infy\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

[Graphics:HTMLFiles/Lecture-13_5.gif]

Out[75]=

Graphics3D

We could make the function better behaved along the z-axis by brute force:

In[76]:=

LeavingKansasNicely [ x_ , y_ , z_ , n_ ] := Module [ { CindRadsq = x ^ 2 + y ^ 2 } , CindRadsq = If [ CindRadsq 10 - 4 , 10 - 4 , CindRadsq , CindRadsq ] ; z n CindRadsq ( CindRadsq + z ^ 2 ) n 2 { y , - x , 0 } ]

In[77]:=

PlotVectorField3D [ LeavingKansasNicely [ x , y , z , 3 ] , { x , - 1 , 1 } , { y , - 1 , 1 } , { z , - .5 , .5 } , VectorHeads True , ColorFunction ( ( Hue [ # * .66 ] ) & ) , PlotPoints 15 , ScaleFactor 0.5 ]

[Graphics:HTMLFiles/Lecture-13_6.gif]

Out[77]=

Graphics3D

Or simply by avoiding the axis altogether and using the symmetry of the field

In[78]:=

PlotVectorField3D [ LeavingKansas [ x , y , z , 3 ] , { x , .01 , 1 } , { y , .01 , 1 } , { z , .01 , .5 } , VectorHeads True , ColorFunction ( ( Hue [ # * .66 ] ) & ) , PlotPoints 15 , ScaleFactor 0.5 ]

[Graphics:HTMLFiles/Lecture-13_7.gif]

Out[78]=

Graphics3D

Calculate the curl of the function using the VectorAnalysis package--note that the coordinate system is specified as cartesian.
For the particular case of n=3:

In[79]:=

Curl [ LeavingKansas [ x , y , z , 3 ] , Cartesian [ x , y , z ] ] // Simplify

Out[79]=

{ 3 x z 2 ( x 2 + y 2 + z 2 ) 5 / 2 , 3 y z 2 ( x 2 + y 2 + z 2 ) 5 / 2 , 3 z 3 ( x 2 + y 2 + z 2 ) 5 / 2 }

Define a new vector function for the curl for general n

In[80]:=

Glenda [ x_ , y_ , z_ , n_ ] := Simplify [ Curl [ LeavingKansas [ x , y , z , n ] , Cartesian [ x , y , z ] ] ]

In[81]:=

Demonstrate the assertion that the curl has a fairly simple form and is sphericaly symmetric for n=1

In[82]:=

Glenda [ x , y , z , n ]

Out[82]=

{ n x z - 1 + n ( x 2 + y 2 + z 2 ) - 1 - n 2 , n y z - 1 + n ( x 2 + y 2 + z 2 ) - 1 - n 2 , n z n ( x 2 + y 2 + z 2 ) - 1 - n 2 }

In[83]:=

Glenda [ x , y , z , 1 ]

Out[83]=

{ x ( x 2 + y 2 + z 2 ) 3 / 2 , y ( x 2 + y 2 + z 2 ) 3 / 2 , z ( x 2 + y 2 + z 2 ) 3 / 2 }

The above is a vector field that points radially from the origin , with a magnitude that falls off like 1 / r 2

Visualize the curl for n=3

In[84]:=

PlotVectorField3D [ Evaluate [ Glenda [ x , y , z , 3 ] ] , { x , 0 , .5 } , { y , 0 , .5 } , { z , 0.1 , .5 } , VectorHeads True , ColorFunction ( ( Hue [ # * .66 ] ) & ) , PlotPoints 7 ]

[Graphics:HTMLFiles/Lecture-13_8.gif]

Out[84]=

Graphics3D

Demonstrate that the divergence of the curl vanishes for the above function independent of n

In[85]:=

DivCurl = Div [ Glenda [ x , y , z , n ] , Cartesian [ x , y , z ] ]

Out[85]=

2 ( - 1 - n 2 ) n x 2 z - 1 + n ( x 2 + y 2 + z 2 ) - 2 - n 2 + 2 ( - 1 - n 2 ) n y 2 z - 1 + n ( x 2 + y 2 + z 2 ) - 2 - n 2 + 2 ( - 1 - n 2 ) n z 1 + n ( x 2 + y 2 + z 2 ) - 2 - n 2 + 2 n z - 1 + n ( x 2 + y 2 + z 2 ) - 1 - n 2 + n 2 z - 1 + n ( x 2 + y 2 + z 2 ) - 1 - n 2

In[86]:=

Simplify [ DivCurl ]

Out[86]=

0


Created by Mathematica  (October 16, 2005) Valid XHTML 1.1!