PHY201, 2000
Donev Aleksandar
This problem is quite interesting and can be solved in many ways, some efficient and well-structured, others quick and sloppy. I will follow the recommendations given in the assignment, which make this look similar to the corresponding Fortran 90 code.
First we choose positions for the 4 charges and their magnitudes, and enter them as matrices (nested lists in Mathematica):
![[Graphics:Images/index_gr_1.gif]](Images/index_gr_1.gif)
The electrostatic potential at a given point with position R is simply the sum of the potentials from the four individual charges. Each of the individual forces is given with U(R)=. I define the potential as a function of the position R where the potential is measured, using the standard Mathematica constructor:
Function[x_]:=Expression with x
Just to make sure there are no numerical singularities, we add a small number to the denominator:
![[Graphics:Images/index_gr_3.gif]](Images/index_gr_3.gif)
Now we can plot this function by setting R={x,y}:
![[Graphics:Images/index_gr_4.gif]](Images/index_gr_4.gif)
Notice that the potential becomes singular near the four charges, but is otherwise fairly smooth in-between. So it is probably better to plot the coutours of the potential surface:
![[Graphics:Images/index_gr_7.gif]](Images/index_gr_7.gif)
And here is the electric field:
![[Graphics:Images/index_gr_10.gif]](Images/index_gr_10.gif)