Flux

In this worksheet, you will examine the flux of the electric field due to a point charge through a cube, with sides of length 2L, centered at the origin.    

Set up the Problem

Define the dimensions of the square box to be L=1:

Clear[x,y,z]

Needs["VectorAnalysis`"]

L=1

Define the unit vectors in rectangular coordinates:

xhat={1,0,0}
yhat={0,1,0}
zhat={0,0,1}

Initially, define the location of the point charge to be at the origin of a rectangular coordinate system:

point={0,0,0}

{a,b,c}=point

Find the electric field of the point charge.

r=((x-a)^2+(y-b)^2+(z-c)^2)^(1/2)

Efield=(q/(4π ϵ))*Grad[-1/r,Cartesian[x,y,z]]

Plot the three dimensional vector field.  For plotting purposes, choose the charge so that ((|q|)/(4π ϵ))=1.

Esubs=Efield/.q->4π ϵ

VectorPlot3D[Esubs,{x,-1,1},{y,-1,1},{z,-1,1},AxesLabel->{x,y,z},VectorPoints->5,VectorScale->Small]

Calculate the flux through the surface (z=L).

E1=Esubs/.z->L

Integrand1=Dot[E1,zhat]

Examine the integrand.

Plot3D[Integrand1,{x,-L,L},{y,-L,L},BoxRatios-> Automatic,AxesLabel->{"x","y"},ColorFunction->Function[{x,y,z},Hue[z]],MeshFunctions->{#3 &}]

Perform the integration.  Put back in the factor of ((|q|)/(4π ϵ)).

Clear[q]

Integrate[Integrate[q/(4π ϵ)*Integrand1,{x,-L,L}],{y,-L,L}]

Calculate the total flux (summed over all six sides of the cube).

Simplify[(q/(4Pi*ϵ))(Integrate[Integrate[Dot[Esubs,xhat]/.x-> L,{y,-L,L}],{z,-L,L}]
+Integrate[Integrate[Dot[Esubs,-xhat]/.x->- L,{y,-L,L}],{z,-L,L}]
+Integrate[Integrate[Dot[Esubs,yhat]/.y-> L,{x,-L,L}],{z,-L,L}]
+Integrate[Integrate[Dot[Esubs,-yhat]/.y->-L,{x,-L,L}],{z,-L,L}]
+Integrate[Integrate[Dot[Esubs,zhat]/.z->L,{x,-L,L}],{y,-L,L}]
+Integrate[Integrate[Dot[Esubs,-zhat]/.z-> -L,{x,-L,L}],{y,-L,L}])]

by Shannon Mayer and Corinne Manogue
Copyright 2020 Corinne Manogue