## Computational Activity: Electrostatic potential and Electric Field of a square of charge

Computational Physics Lab II 2023
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.
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 discretizes a charged square into a sauqre of point charges. Make sure the python function maintians the total charge constant.
2. Write a python function that returns the electrostatic potential from your discretized charge distribution 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.

3. Once you have written the above function, use it to plot the electrostatic potential versus position in the three cartesian directions.
5. On the same figures, plot the potential due to a point charge located at the center of the square, with the same charge as the square (in total). This potential should very closely match your computed potential at distances which are not all that far from your square.

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.

6. Make a 2D contour plot of the equipotential lines in the $z=0$ plane.
7. Write a python function that computes the three components of the electric field vector using $\vec{E}(\vec{r})=\frac{1}{4\pi\epsilon_0}\frac{q}{\lVert\vec{r}\rVert^2}\frac{\vec{r}}{\lVert\vec{r}\rVert^2}$
8. Compute the electric field vector at a position through which one of your contur level passes and visualize it with an arrow.
9. Compute the electric field vector as $\vec{E}(\vec{r})=-\nabla V(\vec{r})$ and plot it on your graph. What do you notice about teh two electric field vectors? What is their relationship with the equipotential line?
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.
Evan more fun
Try a different charge distribution, for example a hollow sphere.

Keywords
integration electrostatic potential surface charge density
Learning Outcomes