Computer Lab 1: Lecture 3

In our computer lab lectures we will work together through concepts and challanges we have discussed over the week in class.  As with your after-class Exercises, you will be expected to turn in your computer lab notebooks before the nect lecture. Please do so by e-mailing your completed *nb file to Pablo Reyes (pmreyes2@illinois.edu), make sure you name the file using the following notation: “MPn_Last_First.nb”, where n is the Lecture number (in this case, 3), and First and Last would be your first and last name.  You will receive full credit for your copmputer lab if it turned in before the next lecture (Lecture n+1).  No late submissions will be accepted.

Objective/Overview:

In your previous exercse, you learned how to calculate Electric Fields from charge distributions using the brute force method and Gauss’s Law.  Gauss’s Law only works well when you have some symmetry in your system, but when you do, it can be a very powerful tool and make your life a lot easier.  In today’s exercise, we will look at how to construct electric fields from superpositions of electric fields we have already calculated using Gauss’s Law.  If we have enough time, we will shoot charged particles through our fields and see what happens!

The Electric Field From a Sheet and Slab of Charge

Sheet of Charge

Suppose we have a sheet of charge with constant surface charge density ρs [C/(m^2)] located on z=0 plane.
We can then express the corresponding charge density function ρ [C/(m^3)] as follows

ρ=ρs DiracDelta[z]

Let’s quickly double-check that we used the DiracDelta function correctly by integrating over all z...

(∫_(-∞)^∞)ρ\[DifferentialD]z

To solve Gauss’s Law for this system we ned to use symmetry, and we NEED to make some assumptions.  You should convince yourself that the Electric Field can ONLY be in the z direction, again using symmetry arguments.  Let’s create our Gaussian Surface as a box or cylinder that is bisected by our plane of charge, as shown in the figure below:

The charge enclosed is then:

qsheet=Integrate[area*ρ,{z,-Infinity,Infinity}]

And the Flux through the ends of the Gaussian Surface (these are the only sides that have an Electric Flux normal to the surface):

fsheet=2*Efield*area

eps0=8.85*10^-12

If we apply Gauss’s Law:

Solve[eps0*fsheet==qsheet,Efield]

Ta-da!!  We now have a value for the E-field!!  (Subscript[E, sheet])=(Subscript[ρ, s])/2(Subscript[ϵ, o]) [V/m], with the direction of the field pointing away from the sheet.  So for a sheet at some point zo, with sheet charge density of 2(Subscript[ϵ, o]) we can write

esheet={0,0,1}*Sign[z-zs]*2*eps0/(2*eps0)

VectorPlot3D[esheet /. zs->0, {x,-1,1}, {y,-1,1}, {z,-1,1}, VectorScale->Small]

Let’s add a graphic of the sheet!

p1=VectorPlot3D[esheet /. zs->0, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p2=Graphics3D[InfinitePlane[{{-1,-1,0},{1,1,0},{-1,1,0}}]];
Show[p1,p2]

We can move our sheet of charge, change its algebraic sign, and plot the new field as

p1=VectorPlot3D[-esheet /. zs->0.5, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p2=Graphics3D[InfinitePlane[{{-1,-1,0.5},{1,1,0.5},{-1,1,0.5}}]];
Show[p1,p2]

If both sheets are present

p1=VectorPlot3D[{esheet /. zs->0}-{esheet /. zs->0.5}, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p2=Graphics3D[InfinitePlane[{{-1,-1,0},{1,1,0},{-1,1,0}}]];
p3=Graphics3D[InfinitePlane[{{-1,-1,0.5},{1,1,0.5},{-1,1,0.5}}]];
Show[p1,p2,p3]

Isnt this cool!

Slab of Charge

We can also use Gauss’s Law to find the field from a slab of finite thickness W, with uniform charge density (Subscript[ρ, o])[C/(m^3)].  Here, we have to be careful.  If we put our Gaussian Surface (box) outside of the slab, our enclosed charge will not change with the length of the box, but if the box is inside the slab, we will have a linear dependence on enclosed charge with increasing box size.  So our resulting E field will be a piecewise expression.  Mathematica can handle this no problem.

So now we can write our expression for enclosed charge:

Clear[ρ,W,eslab,Esum]

qencslab=ρ*If[Abs[z]<W/2,2*z*area,W*area]

And our expression for flux (again assuming symmetry, with all flux going through the ends of our Gaussian Surface):

fslab=2*eslab*area*eps0

Simplify[Solve[fslab==qencslab,eslab]]

We can see that inside the slab, we have a linear dependence on z, but outside the slab, our electric fields looks just like that of a sheet of charge with (Subscript[ρ, s])=W(Subscript[ρ, o]).  So let’s write this as an equation for a slab with (Subscript[ρ, o])=2(Subscript[ϵ, o]) :

ρ=2*eps0; 
eslab={0,0,1}*If[Abs[z]<W/2,z*ρ/eps0,W*Sign[z]*ρ/(2*eps0)]

VectorPlot3D[eslab /. W->1, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}]

Let’s add a graphic of the slab!

p1=VectorPlot3D[eslab /. W->1, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p2=Graphics3D[{Opacity[.4],Cuboid[{-1,-1,-0.5},{1,1,0.5}]}];
Show[p1,p2]

We could also plot the amplitude of the Efield as a function of z

eslab[[3]]

Plot[{eslab[[3]] /. W->1},{z,-1,1}]

Now lets shift and thin down and negate our slab and plot the corresponding E-field:

p3=VectorPlot3D[-eslab /. {W->0.5,z->z-0.25}, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p4=Graphics3D[{Opacity[.4],Cuboid[{-1,-1,-W/2+W/2},{1,1,W/2+W/2} /. W->0.5]}];
Show[p3,p4]

p3=VectorPlot3D[{eslab /. {W->0.5,z->z+0.25}}+{-eslab /. {W->0.5,z->z-0.25}}, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p4=Graphics3D[{Opacity[.4],Cuboid[{-1,-1,-W/2+W/2},{1,1,W/2+W/2} /. W->0.5]}];
p5=Graphics3D[{Opacity[.4],Cuboid[{-1,-1,-W/2+W/2},{1,1,W/2+W/2} /. W->-0.5]}];
Show[p3,p4,p5]

Etop=eslab /. z->z-0.25;
Ebot=eslab /. z->z+0.25;
Esum=Ebot-Etop

Plot[Esum[[3]] /. W->0.5,{z,-1,1}]

OK, so you get the idea...We can create static Electric Fields for a wide variety of structures using our understanding of Gauss’s Law.  Let’s do one more example.

Sphere of Charge

We know, from Exercise 2, what the field should be from a uniform sphere of charge with radius ro.  Let’s write out the piecewise expression in spherical coordinates and then transform to Cartesian so we can plot it.  Here we will use the fact that our system has spherical symmetry, and our field will thus be in the radial direction only.  Let’s solve for the radial component of the field

ClearAll[rho,ro,r];

ersphere=Piecewise[{{rho*r/(3*eps),r<ro},{rho*ro^3/(eps*3*r^2),r≥ro}}]

Our vector field is then

esphere={ersphere,0,0};

espherexyz=TransformedField["Spherical"->"Cartesian",esphere,{r,theta,phi}->{x,y,z}]

Let’s Plot, assuming (Subscript[ρ, o])=2(Subscript[ϵ, o]) , and (Subscript[r, o])=1m:

ro=1;rho=2*eps;p5=VectorPlot3D[espherexyz, {x,-1,1}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}];
p6=Graphics3D[{Opacity[.2],Sphere[{0,0,0},1]}];
Show[p5,p6]

What about moving this somewhere else in space?

espherexyzmove=espherexyz/.{x->x-2}

VectorPlot3D[espherexyzmove, {x,-1,3}, {y,-1,1}, {z,-1,1},VectorScale->{Small,Scaled[0.5]}]

So now you know how to calculate and determine the electric fields from a range of geometric shapes (wires, spheres, slabs, planar surfaces). Now it’s your turn to try one.

Cylinder of Charge

Use Gauss’s Law to calculate the electric field from a cylinder of uniform volumetric charge density. You can assume the cylinder is on the z-axis, with radius “rc” and charge density “rhoc”.  Plot your result in a 3D vector plot.

ecyl=Piecewise[{{rhoc*r/(2*eps0),r<rc},{rhoc*rc^2/(2*eps0*r),r≥ rc}}]

ecylvec={ecyl,0,0}

ecylxyz=TransformedField["Cylindrical"->"Cartesian",ecylvec,{r,theta,z}->{xo,yo,zo}]

p7=VectorPlot3D[ecylxyz/.{rhoc->2*eps0,rc->1}, {xo,-2,2}, {yo,-2,2}, {zo,-2,2},VectorScale->{Small,Scaled[0.5]}];
p8=Graphics3D[{Opacity[.2],Cylinder[{{0,0,-2},{0,0,2}},1]}];
Show[p7,p8]

Collection of Charge Distributions

Using the fields you have developed today, create an Electric Field that is a superposition of 3 or more scaled and shifted fields you have already calculated in class or in the previous notebook.  

Plot the vector fields in 3D.