Computer Simulation: Visualizing Flux through a Cube

Static Fields 2021
Students explore the effects of putting a point charge at various places inside, outside, and on the surface of a cubical Gaussian surface. The Mathematica worksheet or Sage activity shows the electric field due to the charge, then plots the the flux integrand on the top surface of the box, calculates the flux through the top of the box, and the value of the flux through the whole cube.
What students learn
  • Students see that the integrand of the flux through a surface depends both on the distance of the charge from the surface and on the angle between the direction from the surface to the charge and the unit normal to the surface.
  • Students verify the integral form of Gauss's law for examples of charges inside the cube, on the edges or vertices of the cube, and outside the cube.
  • Media
    • 2268/vffluxem.nb

Visualizing Flux through a Cube

Complete this Sage activity or this Mathematica worksheet to explore the flux of the electric field from a point charge through a cube.

Instructor's Guide


We usually walk/talk the students through the worksheet with the charge at the center of the box and then encourage small groups to try putting the charge in other places.

Student Conversations

  • Examining the integrand: With the charge at the center of the box, ask students why the value of the integrand is largest is the center of the top surface of the box. Bring out the fact that the charge is closer to that point of the surface and that the entire electric field vector is perpendicular to the surface there. Draw a picture showing these two aspects of the geometry.
  • Understanding more about how Mathematica works: When students are exploring putting the point charge at other places, point out that sometimes Mathematica can do the flux integrals exactly (often in terms of complicated expressions involving arctangents). (The evalf” command in Mathematica is useful in these cases.) At other times, Mathematica will do the integral numerically. Point out where the worksheet sets various constants to one, so that the integral can be done numerically. Also point out the round-off errors that occur.
  • When the charge is not in the center: When encouraged to explore the consequences of putting the point charge at a variety of positions, many groups will choose points on a face, edge, or vertex of the cube. The Mathematica code is robust enough to handle these situations, yielding \(q\over 2\epsilon_0\), \(q\over 4\epsilon_0\), and \(q\over 8\epsilon_0\), respectively. A few students can be bothered by the idea that an infinitesimal point charge can be partially inside the box and partially outside the box. For these students, returning to the idea of flux and drawing pictures of how much of the electric field points through a side of the box (or is parallel to a side of the box) can be helpful. Electric field lines can also be a helpful representation.


Discuss the relationship between electric flux and the charge enclosed by the surface (namely, Gauss's Law).


This activity is part of two sequences of activities: Geometry of Vector Fields Sequence and Flux Sequence.

Author Information
Corinne Manogue
Learning Outcomes