Activity: Electrostatic potential of a square of charge

Computational Physics Lab II 2022
Students write python programs to compute the potential due to a square of surface charge, and then to visualize the result. This activity can be used to introduce students to the process of integrating numerically.
Now consider a square sheet of charge with side \(L\) and uniform charge density \(\sigma\).

Be aware that pairs may take an hour or more to simply write down the integral that they need to solve. When this happens, remember that it means that the students are getting valuable practice at a skill that is most necessary for them to learn as a physicist!

Issues on paper
  1. We want students to always write \(V(x,y,z)\) or \(V(\vec r)\) or similar on the left side of an equation like \(V=\int\cdots\). Ask students “\(V\) of what?” or “where is that potential?”
  2. Omitting an \(=\) so they don't have an equation. “That doesn't mean anything. It can't be true or false.”

  1. Write a python function that returns the electrostatic potential at an arbitrary point in space.
    1. Many students will need to be told to write down the integral on paper first.
    2. We also want to proactively look for students using scipy quadrature (i.e. numerical integration) functions, and ask them to not use those functions, but instead to program the computation by hand.
    3. When students are confused as to how to do an integral numerically, ask then what an integral really is, and after a few statements they may get to either Riemann sums or chopping and adding, and either way works well. One can also think of it as treating the sheet as if it were a whole bunch of point charges.
    4. Another common student challenge here is wanting to use the range function with non-integer inputs. You can point out this error, and ask what they might google to find a better function. Something like “python range non-integer” (or float) works well.
  2. Once you have written the above function, use it to plot the electrostatic potential versus position in the three cartesian directions.
  3. Label your axes.
  4. On the same figures, plot the potential due to a point charge located at the center of your square, with the same charge as your square (in total). This potential should very closely match your computed potential at distances which are not all that far from your square.

    Note that this is the first term in a power series expansion far from the origin. I just didn't bother forcing you to work it out yourself.

    The most frequent bug is to omit the dx in the integral, and this reveals itself when they do this comparison, but often students don't even notice. They think it agrees because both curves approach zero. So you need to actually look and inform them that there is a problem.

  5. Try constructing other visualizations.
Extra fun
What do you expect your potential to look like far from the square of charge? Verify this graphically!
More fun
What happens when you change the number of grid points used to perform the integral?
Subtle fun
What do you expect your potential to look like close to the center of the square of charge? See if you can make a prediction using Gauss's Law, if you can remember it from your introductory physics. With or without a prediction, you can examine the behavior close to the center of the square of charge.

Learning Outcomes
  • ph366: 1) Write functions and entire programs in python
  • ph366: 2) Apply the python programming language to solve scientific problems
  • ph366: 3) Use the matplotlib and numpy packages
  • ph366: 4) Model the physical systems studied in the course