Category Archives: Peter

Critique: Modeling Electric and Magnetic Fields

At the end of the preliminary data section, the Electric Field of a bar electret is stated to be approximately that of two opposing charged point charges at either end of the bar. However, little explanation is given as to why the bar can be modeled that way. If there was a justification given for this model, such as modeling many charges arranged in a line to show that the net fields cancel aside from the two charges at either end, the data would significantly benefit from this. Finally, it is unclear in the final data whether or not you are modeling a bar electret or an electric dipole.

Additionally, it is unclear why you chose the specifications for the dipole bar magnet, as well as the surrounding constants and values for the other scenarios. Although it is clear from a knowledgeable individual’s standpoint why the charges were assigned the equations as they were, a layperson may not be able to interpret the equations correctly.  Additionally, including the full derivations for each scenario on the preliminary data in mathematica would streamline the analysis of the data significantly, as the constants themselves would become more clear with this. Additionally, the equations that yield the specific graphs in the final data you are showing should be wrote, so that I we can associate the data and figures easily.

Finally, I suggest making the equations and derivations slightly more robust. By that I mean carrying out the derivations for these geometries in matter, as to better replicate the situations which a student may come across. Currently, this issue is approached without giving thought to the effects of polarization and the various materials involved. This may prove to both improve the depth and breadth of the project. Another concern that I have, although it may be a fault with mathematica, is that the field of the electret, does not show the field’s shape clearly. I suggest using a different graphing method, perhaps a contour graph, which would allow the interpretation of field lines much more intuitively. As such we would then expect the graph to take the shape of an imperfect dipole, as stated in your data.


Final Remarks

In this post, I will discuss the results of the final data, what I learned, and suggestions for further work.

I began by using one of the most fundamental and well known laws in electromagnetism: Gauss’s Law. It allows for the relatively simple modeling of electric fields of various geometries, where the direct formula for the electric field would have been difficult, if not impossible, to use.

I used this law to derive some the electric fields of some more common physical geometries dealt with in undergraduate physics, which the exception of one configuration: the electric dipole. Through this process I not only re-affirmed my knowledge of the principals involved but learned how to communicate them in an effective way. I then used Mathematica to model the derived electric fields to provide a visual representation.

This was particularly challenging as I do not had a significant background with computer programing at all, let alone with Mathematica. From this work I significantly improved my working knowledge and understanding of this software, not only through the programing but through explaining what was being done throughout the code.

The final results displayed how the electric field of the particular configurations of a sphere, cylinder and ideal dipole work and these results agreed with known models. The basic principles showed that electric fields point away from positively charged objects and towards negatively charged ones, which is most clearly seen in the model of the dipole.

Further work with this topic ideally would include the modeling of more complex systems, such as multiple spheres or cylinders of varying charge or charge densities. It would also be interesting to compare the magnetic field configurations of similar objects, which unfortunately was not able to be done as originally planned due to limitations of Mathematica and available working material.


Final Data

My final data builds significantly from the preliminary data sets. In that set, I derived the equations for the electric field of a sphere, cylinder and the approximation of an electric dipole. Those were:

    \[ \textbf{E}  = \frac{q_e}{\epsilon_0 4 \pi r^2} \textbf{$\hat{r}$} \]

    \[ \textbf{E} = \frac{\rho R^2 }{2r\epsilon_0} \textbf{$\hat{r}$}  \]

Where the dipole was approximated as two point charges of opposite charge (i.e. two spheres of opposite charge).

I went back to mathematica and overlaid a 3-D model of a small sphere on the previously plotted vector field of the electric field of a sphere, pictured below.


The same was done for a cylinder, both cases allowed for it to be seen how the geometries affected the electric fields.


For the electric dipole, an additional approach was taken to find the electric field. The equation for the electric potential of an “ideal” dipole is given as

    \[ V  = \frac{p_o \cos(\theta)}{\epsilon_0 4 \pi r^2} \]

For the purposes of simplification in Mathematica, the equation was re-written to absorb all the constants into one term:

    \[ V  = \frac{p \cos(\theta)}{r^2} \]

Now to find an expression for the electric field, use the formula:

    \[ \textbf{E} = -\nabla V \]

Which Mathematica can interpret and plot accordingly as:


For a better view of how the vectors are interacting, look at this 2-D plot of the same field:


The code for the following models can be found here: Final Data


Preliminary Data

The first item to be modeled will be the electric field of a sphere of uniform charge density. This will set the basic framework for any fields based off of a sphere.

To start, imagine a conducting solid sphere of some radius “R” that contains a total charge of Q. There are a couple of ways that the electric field of this configuration could be found. One is Coulomb’s Law, given by:

    \[ E(r)= \frac{1}{4\pi\epsilon_0} \int {\frac{\textbf{$\hat{r}$}}{r^2}  dq \]

Where $ \epsilon_0 $ is the permittivity of free space and $ r $ is the separation between the source and the test.

The other (and far easier) is to use Gauss’s Law, given by:

    \[ \oint _S {\textbf{E} \cdot d\textbf {a} = \frac{1}{\epsilon_0} q_e \]

Where $q_e$ is the enclosed charge of a Gaussian surface, $\textbf{E}$ is the electric field. Note that we are also taking a surface integral. All the math looks interesting, but what is a Gaussian surface? A Gaussian surface is an arbitrary surface at some distance from our actual surface (in this case our actual surface is the previously mentioned sphere), that matches the symmetry of the electric field generated by the object in question. What that means is that the electric field of our real object “flows” through the Gaussian surface in the same way it does the real object. Once this surface has been drawn we can use Gauss’s law to solve for the electric field of the object. In our case, the Gaussian surface is a sphere around out real sphere of some radius that is greater than $R$.

Now, because of symmetry, we can make a few nice simplifications. First, since the magnitude of the electric field is constant (the sphere is uniformly charged) $\textbf{E}$ can be taken outside of the integral, leaving the only thing inside to be $d\textbf {a}$. The integral of that is simply “A” but recall that this was a surface integral, so A is the surface area of our Gaussian surface, a sphere, which is simply $4 \pi r^2$.

Now all we have left is

    \[ \textbf{E}\ (4 \pi r^2) = \frac{1}{\epsilon_0} q_e \]

Which is easily re-written as

    \[ \textbf{E}  = \frac{q_e}{\epsilon_0 4 \pi r^2} \textbf{$\hat{r}$} \]

and there is it. The electric field of a sphere (Griffith’s Example 2.2).

The electric field plotted 3D in mathematica:


Next, we’ll find the electric field of a cylinder of length L and radius R with a uniform volume charge density $\rho$. Again, it will be quite a bit easier to determine this using Gauss’s Law:

    \[ \oint _S {\textbf{E} \cdot d\textbf {a} = \frac{1}{\epsilon_0} q_e \]

Just like the sphere we draw a surface that matches the symmetry of our object, and since we want the field outside the cylinder, we again choose a surface that has a radius greater than R, which I’ll call r.

Following the same line of reasoning as the sphere, the left side of the equation can be simplified to just the electric field, E, multiplied by the surface area of the surface. The surface area of a cylinder is given by $2\pi r l$ where $l$ is just the length of of Gaussian cylinder. This lets us write:

    \[ \textbf{E}\ (2 \pi r l) = \frac{1}{\epsilon_0} q_e \]

From here we need to find a way to express our charge enclosed. The definition of volume charge density is the total charge over the total volume, meaning that total charge is equal to charge density multiplied by the volume of the object. Again call our total charge Q and we know the volume of a cylinder to be $\pi r^2 l$. Taking our radius as R we can now write our Gauss’s law expression as:

    \[ \textbf{E}\ (2 \pi r l) = \frac{\rho\ \pi R^2 l}{\epsilon_0}  \]

Solving for $\textbf{E}$ yields:

    \[ \textbf{E} = \frac{\rho R^2 }{2r\epsilon_0} \textbf{$\hat{r}$}  \]

Which is nicely plotted as:


(excerpt from Griffith’s problem 2.16)

Finally, we have the electric field of a bar. The  electric field analogue to a bar magnet is whats known as a bar electret. For this type of model, we will assume that the electret’s shape is similar to the more common picture of a bar – that is that it’s length is much greater than its width.

This electret requires us to use something other than Gauss’s Law. In this configuration the electric field is approximately that of two point charges of opposite charge. The electric field of a point charge is given by:

    \[ \textbf{E}  = \frac{q}{\epsilon_0 4 \pi r^2} \textbf{$\hat{r}$} \]

The plots shown below are of the two points of opposite charge.

npoint      and sphere

The mathematica code for these figures may be viewed here: Preliminary Data


Further modeling may show more complex systems build off of the ones shown here.


Project Plan: Modeling Electric and Magnetic Fields

What will be modeled:

I will be modeling the electric fields of a bar magnet, cylinder and sphere. The derivations of the field geometries will be shown in a step by step process and then will be modeled with Mathematica. More complex systems taken from examples in Introduction to Electrodynamics may be used an modeled as well, time permitting.


April 7-April 14: Complete project proposal and begin derivations

April 14-April 21: Alter project proposal as needed and completed derivations

April 21- April 28: Post derivations and begin Mathematica modeling

April 28-May 5: Final Mathematica modeling and combination with Cedric’s Modeling


I will be working with Cedric Chang who will derive and model the magnetic fields of the same objects that I model the electric fields of. At the end, both of our models will be combined to display both electric and magnetic fields of the shapes in question.


Introduction to Electrodynamics by David J. Griffiths, Third Edition


Modeling Electric and Magnetic Fields

For my project, I will work with Cedric Chang and study the electric and magnetic fields of a bar magnet, cylinder, and sphere. I will specifically be modeling the electric fields and will begin by deriving the Electric fields for each geometry using Gauss’s Law. Then I will use Mathematica to model the vector fields of each in three dimensions. Problems from David Griffiths’ Introduction to Electrodynamics, Third Edition may be used as examples of these kinds of geometries. These will be combined with the magnetic field of each object from Cedric and compared.