5. Electrostatics

Legal Notice, Disclaimer, and Book Ordering Information:

Null

Setup

\(Clear["Global`*"]; 
Off[General::spell]; 
Off[General::spell1]; 
    \)

Needs["Calculus`VectorAnalysis`"]

Needs["Graphics`PlotField`"]

Needs["Graphics`PlotField3D`"]

<< "D:\Mma\Inits\ch5init.m"

Clear["Global`*"];

5.2 Problems

5.2.3  Legendre Polynomials and Spherical Harmonics

Problem 1:  A charged ring

Consider a uniformly charged ring of radius r0 and total charge q.

Part (a)   Find the potential along thr z-axis.  Find the expansion of the potential in the limit r->0 and r->∞.

potZ=q/Sqrt[r^2+a^2]

potZin[n_]:= Series[potZ,{r,0,n}]//PowerExpand//Normal

potZout[n_]:= Series[potZ,{r,Infinity,n}]//PowerExpand//Normal

potZin[9]

potZout[9]

Part (b)   Find the series expansion for the potential at all points in space.

Clear[pot,A,B]

pot[s_]:= Sum[(B[n] r^n + A[n] (a/r)^(n+1) ) LegendreP[n,Cos[θ]],{n,0,s}]

pot[2]

coeffOut[s_]:=
	Solve[0==CoefficientList[
	((pot[s]-potZout[s])//.{B[i_]->0,θ->0,r->1/w}),w]
	,list1[s]]//Flatten

list1[s_]:=A[#]&/@Range[0,s]

list1[3]

coeffOut[3]

Clear[potOut]

potOut[s_]:=pot[s]//.Join[coeffOut[s],{B[x_]->0}]

eq2 = potOut[6]

potZout[9]-(potOut[9]/.θ->0)==0

coeffIn[s_]:=
	Solve[0==CoefficientList[
	((potZin[s]-pot[s])//.{A[x_]->0,θ->0}),r]
	,list2[s]]//Flatten

list2[s_]:=Table[B[n],{n,0,s}]

list2[3]

coeffIn[3]

Clear[potIn]

potIn[s_]:=pot[s]//.Join[coeffIn[s],{A[x_]->0}]

eq4 = potIn[4]

Part (c)   Find the electric field at all points in space.

SetCoordinates[Spherical[r,θ,ϕ]]

electOut[s_]:= -Grad[potOut[s]]

electOut[3]

electIn[s_]:= -Grad[potIn[s]]

electIn[3]

Part (d)   Express the potential in Cartesian coordinates and plot this in two and three dimensions.  Plot in the plane of the ring and normal to this plane.  Plot the equipotential surfaces and electric field lines.

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

values={a->1,q->1}

potOutXYZ=potOut[4]//.r2xRule//.values//Together

potInXYZ[x_,y_,z_]:=potIn[4]//.r2xRule//.values//Together

Clear[ff]

ff[x_, y_, z_] = 
   Evaluate[If[N[x^2 + y^2 + z^2] > 1, 
     (x^2 + 4*x^4 + y^2 + 8*x^2*y^2 + 4*y^4 - 2*z^2 + 8*x^2*z^2 + 
        8*y^2*z^2 + 4*z^4)/(4*(x^2 + y^2 + z^2)^(5/2)), 
     1/64*(64 + 16*x^2 + 9*x^4 + 16*y^2 + 18*x^2*y^2 + 9*y^4 - 32*z^2 - 
        72*x^2*z^2 - 72*y^2*z^2 + 24*z^4)]];

ff[1,0,0]

Plot[ff[x,0,0],{x,-2,2}];

Show[GraphicsArray[
	{Plot3D[ff[x,0,z],{x,-2,2},{z,-2,2},PlotPoints->20]
	,ContourPlot[ff[x,0,z],{x,-2,2},{z,-2,2},PlotPoints->20
	,ContourSmoothing->True
	,ColorFunction->Hue]
	}]];

VEPlot[ff[x,0,z],{x,-2,2},{z,-2,2}];

Show[GraphicsArray[
	{Plot3D[ff[x,y,0],{x,-2,2},{y,-2,2},PlotPoints->20]
	,ContourPlot[ff[x,y,0],{x,-2,2},{y,-2,2},PlotPoints->20
	,ContourSmoothing->True
	,ColorFunction->Hue]
	}]];

VEPlot[ff[x,y,0],{x,-2,2},{y,-2,2}];