## Computational Activity: Electrostatic potential of spherical shell

Computational Physics Lab II 2022
Students solve numerically for the potential due to a spherical shell of charge. Although this potential is straightforward to compute using Gauss's Law, it serves as a nice example for numerically integrating in spherical coordinates because the correct answer is easy to recognize.
Now consider a spherical shell of charge with uniform surface charge density $\sigma$.
1. Decide which coordinate system to use for the point where you are asking the potential, and which coordinate system to use for locating your point on the surface.
The integral needs to be done in spherical coordinates. The point where the potential is evaluated can be given in either rectangular or shperical coordinates. Life is easier if it's given in rectangular, but most students use spherical.
2. Write down on paper an integral to find the potential.

The hard things here are to find the distance between the two points, and to remember how to find the small chunk of area.

Also remembering to specify where they are finding the potential. i.e. we frequently see things like: \begin{align} V &= \int_0^{\pi}\int_{0}^{2\pi} \frac{k\sigma}{\sqrt{R^2+r^2-2rR(\cos\theta\cos\theta' +\sin\theta\sin\theta'\cos(\phi-\phi'))}} R^2\sin\theta d\phi d\theta \end{align} where it's not clear or consistent which thing has the primes. We try to emphasize to the class that it is essential to write $V(r,\phi,\theta)$ (or whatever) on the left hand side of the equations. It's also common to have no equals sign at all, which is of course even worse.

3. Write a python function $V(\vec r)$ that returns the electrostatic potential at a specified point in space.
4. Once you have written the above function, use it to plot the electrostatic potential versus position in the three cartesian directions.

It is very common at this point is to use negative $r$ values when plotting the potential e.g. as a function of $x$. This does give correct plots, but is also a bit weird. At this stage, we should probably let it pass.

You will probably also find students expecting the potential to be zero inside the sphere, because they know the electric field is zero inside a solid sphere. I think it's worth engaging with students who think this, asking if the potential is continuous at the surface (if not, then the electric field must be infinite), and bringing them towards remembering that the potential is the integral of the electric field.

5. Show (by plotting) that your potential at large distances converges to the potential of a point charge with the same total charge as your sphere.
It is common at this stage for students to still believe that where there is charge the potential should be infinite. Looking at their numerical results can sometimes help, but it is also helpful to ask students why they think the potential should be infinite. One can then bring in Gauss's Law (if it has been covered) to help clear up why the electric field is infinite for a point charge, and not for a planar charge distribution.
6. Try constructing other visualizations.
Creating a 2D plot (a contourf or a pcolor is a bit challenging if their $V$ takes spherical coordinates. The simplest approach in this case is to define an X, Y = np.meshgrid(x,y) and then compute the spherical coordinates from those using arc-trig. To do this correctly almost requires arctan2.
Extra fun
Modify your code to find the potential of one octant of a spherical shell (e.g. the portion when $x>0$ and $y>0$ and $z>0$). Do your visualizations still all make sense?
This is a great way to discover that there were bugs in the visualization, e.g. using arctan rather than arctan2. I'd rather enable students to discover that they have bugs using symmetry if at all possible.
Solid fun
Try a solid sphere of charge only if you have done all the tasks above. How does it behave inside the sphere?

Keywords
electrostatic potential spherical coordinates
Learning Outcomes