Electrostatic pics in 2D

By analogy with Coulomb’s law in 3D, we might consider a 2D electrostatic field that arises from a point charge q at the point (Subscript[r, 0])=⟨(Subscript[x, 0]),(Subscript[y, 0])⟩ at the point r=⟨x,y⟩. I guess we’d again get

E(r)=(1/(4π (Subscript[ϵ, 0])))(q/(r^2))u,

where r=‖r-(Subscript[r, 0])‖, and u is a unit vector in the direction of r-(Subscript[r, 0]). Let’s see what this might look like.

A single point charge

Mathematica formulation

Note that u/(r^2) can be written

(u/(r^2))=((r-(Subscript[r, 0]))/((‖r-(Subscript[r, 0])‖)^3))=((r-(Subscript[r, 0]))/((((r-(Subscript[r, 0]))·(r-(Subscript[r, 0]))))^(3/2))).

Thus, in Mathematica, we can write

electricField[{q_,r0:{x0_,y0_}}][r:{x_,y_}] := 
With[{v=r-r0},q*v/(((v.v))^(3/2))];

For example, we can compute the the electric field for a single, negative point charge centered at the origin.

field = electricField[{-1,{0,0}}][{x,y}]

Visualization of the field

We can plot this with Mathematica’s StreamPlot command.

fieldPlot = StreamPlot[field,{x,-2,2},{y,-2,2}]

The potential

The potential of the field is a scalar function whose negative gradient is the field. A simple check shows that we can write the potential as

V(r) = (q/(‖r-(Subscript[r, 0])‖)).

We can write this in Mathematica and compute the potential for a single point charge as

electricPotential[{q_,r0:{x0_,y0_}}][r:{x_,y_}] := 
With[{v=r-r0},q/(((v.v))^(1/2))];
potential = electricPotential[{-1,{0,0}}][{x,y}]

Visualization of the potential

We can plot the potential together with the field.

potentialPlot = ContourPlot[potential, {x,-2,2},{y,-2,2},ContourShading -> False,ContourStyle -> Directive[Thick,Lighter[Red]]];
Show[{fieldPlot,potentialPlot}]

Several charges

The principle of superposition says that we can combine the fields of several point charges by simple addition. Thus, here’s the field created by several points.

q1={-2,{0,1}};
q2={1,{1,1}};
q3={1,{-1,1}};
q4={-1,{0,0}};
charges = {q1,q2,q3,q4};
field = Total[Simplify[electricField[#][{x,y}]& /@ charges]]

And the potential

electricPotential[{q_,r0:{x0_,y0_}}][r:{x_,y_}] := 
With[{v=r-r0},q/(((v.v))^(1/2))];
potential = Total[electricPotential[#][{x,y}]& /@ charges]

Let’s plot it all together with the point charges.

point[{q_,p:{x_,y_}}, r_:0.1] := Module[{color},
color = If[q<0,Red,Green];
{{Lighter@color,Disk[p,r*Abs[q]]},Circle[p,r*Abs[q]]}];
cp = ContourPlot[potential, {x,-2,2},{y,-1,2},
ContourShading -> False, ContourStyle -> Directive[Thick,ColorData[1,2]]];
sp = StreamPlot[field, {x,-2,2},{y,-1,2},StreamPoints -> 99];
Show[{cp,sp,Graphics[point /@ charges]}, AspectRatio->Automatic]

The divergence

Div[{-(x/((((x^2)+(y^2)))^(3/2))),-(y/((((x^2)+(y^2)))^(3/2)))},{x,y}]//Simplify

I wonder if there’s an easier way to find that result by hand?