Students write python programs to compute and visualize the potential due to four point charges. For students with minimal programming ability and no python experience, this activity can be a good introduction to writing code in python usingnumpy
andmatplotlib
.
This is a great first programming activity.Consider a system consisting of four point charges arranged on the corners of a square in 3D Cartesian space of coordinates \((x,y,z)\).
Write a python function that returns the potential at any point in space caused by four equal point charges forming a square. Make the sides of the square parallel to the \(x\) and \(y\) axes and on the \(z=0\) plane.
To do this you will need the expression for a the potential due to a single point charge \(V= \frac{k_Cq}{r}\) where \(r\) is the distance from the point charge. You will also need to use the fact that the total potential is the sum of the potentials due to each individual point charge.
It is important that we ask students first to create a function for the potential, and only then try to visualize the potential. This allows students to reason about the computation for a single point in space (defined in their choice of coordinate systems).
Since the students have already written a function for their potential, they can create a plot by creating an array for \(x\) (or \(y\), or \(z\)), and then passing that array to their function, along with scalars for the other two coordinates. Many students will discover this simply by modifying an example script they find on the web, replacing \(\sin(x)\) or similar with their function. It is well worth showing this easier approach to students who attempt who attempt to write a loop in order to compute the potential at each point in space.
We ask students to explicitly plot the potential along axes because students seldom spontaneously think to create a 1D plot such as this.
This may need to be omitted on the first Tuesday of class, since students probably will not yet have seen power series approximations. It may work in this case to at least talk about what is expected at large distance, since "it looks like a point charge" is reasoning students do make.
Students struggle with the \(x\) approximations (assuming the square is in the xy plane). Each pair will probably need to have a little lecture on grouping terms according to the power of \(x\), and keeping only those terms for which they have every instance.
Common visualizations for 2D slices of space include contour plots, color plots, and "3D plots". Another option (less easy) would be to visualize an equipotential surface in 3 dimensions. It is worth reminding students to consider other planes than those at \(x=0\), \(y=0\), and \(z=0\).