Useful Stuff for Chapter 3:

Packages

You may want to turn off the spell checker before starting this chapter:

Off[General::spell ]; 
Off[General::spell1];
Off[Clear::wrsym];

There are several packages that are used in this chapter:

Needs["Calculus`VectorAnalysis`"]
Needs["Graphics`Graphics`"] 
Needs["Graphics`Graphics3D`"] 
Needs["Graphics`ParametricPlot3D`"] 
Needs["Graphics`PlotField`"] 
Needs["Graphics`PlotField3D`"]

Care must be taken in loading these packages to avoid shadowing. It is safest to load the packages at the start.

User-defined procedures

It is useful to create user-defined procedures for calculations that are used repeatedly.  We illustrate how to analyze these procedures by examining the steps one at a time.  Some  procedures will fail in particular cases, and you are encouraged to write conditional statements to handle them.

Monopole

Complex charge distributions can always be represented by a sum of point charge distributions. We use this superposition principle repeatedly, so it is useful to define a function to compute the potential distribution of a charge in a general manner. The Monopole  function will do this in any dimension: Monopole

Monopole::usage="Monopole[q,{x0,y0,z0},{x,y,z}] 
computes the potential due to a monopole of charge q 
located at position {x0,y0,z0} in {x,y,z} coordinates.";

Monopole[q_:1,r0_:{0,0,0},r_:{x,y,z}]:= 
   q/Sqrt[ Sum[(r0[[i]]-r[[i]])^2,{i,1,Length[r0]}] ];

The specific formula is: V = (q/(Sqrt[(∑_(i = 0)^D) ((((Subscript[r, 0])(i)  -  r(i)))^2)])), where  D  is the dimension of the vector.

Example

Consider a simple two-dimensional example with specified coordinates:

Monopole[charge,{1,2},{x,y}]

We can repeat this example taking advantage of the default coordinates {x,y,z}:

Monopole[charge,{1,2}]

A dipole is easily formed from two monopoles:

dipole= ( Monopole[+1,{0,0,-a/2}] + 
          Monopole[-1,{0,0,+a/2}] )

Note that this definition of Monopole will work for arbitrary dimension.

One can also make another definition of monopole shown below utilizing the Dot product; however this definition will not allow the defaults to be used in 1-Dimension or 2-Dimensions.

monopole[q_:1,r0_:{0,0,0},r_:{x,y,z}]:= q/Sqrt[(r0-r).(r0-r)];
monopole[charge,{1,2}]  (* This does not work *)

x2rRule

x2rRule =  {x, y, z}  ->  
          CoordinatesToCartesian[{r, θ, ϕ}, Spherical]  // 
        Thread

r2xRule

r2xRule =  {r, θ, ϕ}  ->  
          CoordinatesFromCartesian[{x, y, z}, Spherical]  // 
        Thread

Protect User-defined Procedures

Protect[Monopole,x2rRule,r2xRule];

Monopole at Origin:

Clear["Global`*"]

field =  Monopole[+1, {0, 0, 0}]   /. {x -> 0}

p1 = 
        ContourPlot[ field, {y, -3, 3}, {z, -3, 3}, 
          ContourShading -> False];

p2 = 
        PlotGradientField[ field, {y, -3, 3}, {z, -3, 3}, 
          ScaleFunction -> (1 &)];

Show[p1, p2];

fieldR = field /.x2rRule

fieldR +  O[r, ∞]^4   // Simplify  // 
        PowerExpand  // Simplify

series =  Series[ fieldR, {r, ∞, 4}]  // Simplify  // 
          PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

series =  Series[ fieldR, {r, ∞, 10}]  // 
            Simplify  // PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

Monopole NOT at Origin:

Clear["Global`*"]

field =  Monopole[+1, {0, 0, 0}]   /. {x -> 0}

p1 = 
        ContourPlot[ field, {y, -3, 3}, {z, -3, 3}, 
          ContourShading -> False];

p2 = 
        PlotGradientField[ field, {y, -3, 3}, {z, -3, 3}, 
          ScaleFunction -> (1 &)];

Show[p1, p2];

fieldR = field /.x2rRule

fieldR +  O[r, ∞]^4   // Simplify  // 
        PowerExpand  // Simplify

series =  Series[ fieldR, {r, ∞, 4}]  // Simplify  // 
          PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

series =  Series[ fieldR, {r, ∞, 10}]  // 
            Simplify  // PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

Dipole at Origin:

Clear["Global`*"]

field =  Monopole[+1, {0, 0, 0}]   /. {x -> 0}

p1 = 
        ContourPlot[ field, {y, -3, 3}, {z, -3, 3}, 
          ContourShading -> False];

p2 = 
        PlotGradientField[ field, {y, -3, 3}, {z, -3, 3}, 
          ScaleFunction -> (1 &)];

Show[p1, p2];

fieldR = field /.x2rRule

fieldR +  O[r, ∞]^4   // Simplify  // 
        PowerExpand  // Simplify

series =  Series[ fieldR, {r, ∞, 4}]  // Simplify  // 
          PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

series =  Series[ fieldR, {r, ∞, 10}]  // 
            Simplify  // PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

Dipole NOT at Origin:

Clear["Global`*"]

field =  Monopole[+1, {0, 0, 0}]   /. {x -> 0}

p1 = 
        ContourPlot[ field, {y, -3, 3}, {z, -3, 3}, 
          ContourShading -> False];

p2 = 
        PlotGradientField[ field, {y, -3, 3}, {z, -3, 3}, 
          ScaleFunction -> (1 &)];

Show[p1, p2];

fieldR = field /.x2rRule

fieldR +  O[r, ∞]^4   // Simplify  // 
        PowerExpand  // Simplify

series =  Series[ fieldR, {r, ∞, 4}]  // Simplify  // 
          PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];

series =  Series[ fieldR, {r, ∞, 10}]  // 
            Simplify  // PowerExpand  // Simplify

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -3, 
          3}, {z, -3, 3}, ScaleFunction -> (1 &)];

PlotGradientField[ Normal[series] /. 
              r2xRule  /. {x -> 0}  // Evaluate, {y, -10, 
          10}, {z, -10, 10}, 
        ScaleFunction -> (1 &)];