First, I would like to blame Frank Noschese (@fnoschese) for this post. Some time ago, he posted this on twitter.
Unwinding by writing VPython code to brute force calculate the electric flux thru the face of a cube. #iknowyourejealous
— Frank Noschese (@fnoschese) April 26, 2013
The idea is simple: numerically calculate the electric flux through some surface.
What the Heck is Flux?
Is this the same as a flux capacitor? No. In physics, we say flux is a way to measure the field that interacts with some surface. I know, that definition is not so great – mostly because we usually deal with flux in cases of make-believe surfaces. You’ll see what I mean in a bit.
Let me start with something silly. What if we had something called rain flux? Rain flux is a measure of the rate that rain hits some surface.
In this model, there are three things you could change that would change the rain flux.
- The rain rate.
- The size of the area.
- The angle between the area and the rain.
In general, you can calculate the the flux for any vector field and area. Suppose I have some field labeled as “C”. The flux would be:
Of course, this assumes that the vector field (C) is constant over the surface area A. What if either the area is curved or the field is not constant? In that case, you would have to break the surface area into infinitely small pieces and calculate the flux for each tiny piece. The sum of these tiny fluxes is the total flux. Sounds like integration doesn’t it? It is. In general, it can be written as:
The integral is over some area (so, if you actually integrated it might be a double integral).
So, that’s flux. What about electric flux? It turns out that if you find the total electric flux for some closed surface (a full surface that covers some volume) then it is proportional to the net electric charge inside that surface. This is Gauss’s Law.
The little circle on the integral sign means that it is a closed surface area integral.
Typically, Gauss’s Law is used to calculate the magnitude of the electric field due to different charge distributions. However, you have to know something about the direction of the electric field in order to even use Gauss’s Law. Here is the classic example using this law to determine the electric field due to a point charge.
Suppose I have a positive charge, q. Now if I draw an imaginary sphere around this charge, I can think of the electric field and flux through this sphere.
Since I know that the electric field is spherically symmetric around this point charge, I know the direction of the electric field on this imaginary sphere. Better yet, I know the magnitude is constant and perpendicular to the surface area. This means that at each point on this surface, the differential flux is constant. This makes the surface integral trivially easy.
Here’s what happened above: the vector E and dA were in the same direction all over the surface. This means that the dot product between these two is just the product of their magnitudes. Further, since E is constant, it came out of the integral. What’s left is just the surface integral over the sphere – this gives the surface area of a sphere.
Now, if I combine this with Gauss’s Law I can solve for the magnitude of the electric field.
BOOM. The electric field due to a point charge. But hold on. It’s not all that great. Remember I made the assumption that the field was spherically symmetric. Also, this just gives me the magnitude of the field. But it’s still pretty cool.
Numerical Calculation of Flux
I always tell my students that Gauss’s Law works for all shapes. It doesn’t have to be a sphere, you could put a charge inside a cube and calculate the flux. As long as it’s the same charge inside, it will be the same total flux. It doesn’t matter what the shape is.
When we use Gauss’s Law, we like to pick surfaces over which the integral is super simple (like above). But could you actually calculate the flux for a point charge in a box? Yes. Let’s do it. Here is the basic plan.
- Make a point charge at some location.
- Start with one face of the cube – let’s say the one in the positive z direction.
- Scan over this face in small square pieces.
- For each piece, calculate the electric field at the center of this square.
- Use the area of the small square and the electric field to calculate the flux.
- Repeat for all other squares.
- Add up all the tiny pieces of flux.
That’s not too bad. Really, the only tricky part is making sure you “scan” over the face of the cube in the correct way. Here is a link to this program. I went over the six cube faces individually instead of writing some face calculating function – it’s just easier to see what’s going on in that case. Also, to represent the flux through each tiny area I used different shades of red for positive flux and blue for negative flux.
You should download the code and play with it (you will need to have the VPython module installed). The image at the top shows a sample run with a positive charge in the middle of the cube. Here is what it looks like if the charge is outside the box.
You can see in this case, the side nearest the positive charge is blue to represent negative flux. For the rest of the cube, the flux is positive (some parts are dark since the flux is very small). The total flux in this case is very close to zero. For the case here, each face is broken into 5 x 5 smaller squares. This produces a total flux of -0.292 V*m.
Now let’s play. What happens if you increase the number of squares for the calculation? Here is a plot of the total flux as a function of n (up to n = 200).
Just to be clear, for the case of n = 200, there are actually 200 x 200 squares for each cube face. That means a total of 240,000 flux squares. You can see that the flux calculated from the numerical method quickly approaches the theoretical value of the flux from Gauss’s Law.
I think that there may be an error in my program. It seems like for some values of n, the cube doesn’t fill in all the way. It probably has something to do with the way I have my while loop set up. I bet I could fix this by using a for loop instead. Oh well, maybe you can fix this for a homework assignment.
What About a Dipole?
The posted program only has one charge. You can move it where ever you like, but it’s just calculates the field due to one charge. What if I change it so it works with more than one charge? I’m not going to show you the code for this, instead I will leave it as a homework assignment.
Here is the Gauss’s Law cube with a dipole inside.
For this case, the numerical value of the flux is 1.89 x 10-15 V*m which is pretty much as close to zero as you would like to expect. Remember, the total charge inside is also zero Coloumbs.
It’s not just a numerical calculation, it’s art.Go Back to Top. Skip To: Start of Article.