Exploring Maxwell’s Equations with Mathematica 9

September 19, 2013 — Itai Seggev, Senior Kernel Developer, Algorithms R&D

I love Maxwell’s equations. As a freshman in college, while pondering whether to major in physics, computer science, or music, it was the beauty of these equations and the physical predictions that can be elegantly extracted from them that made me decide in favor of physics. On a more universal level, the hints in Maxwell’s equations led Einstein to write Zur Elektrodynamik bewegter Körper (“On the Electrodynamics of Moving Bodies”), more commonly known as Einstein’s first paper on the theory of relativity. The quantum version of the equations, quantum electrodynamics (QED), remains our most successful physical theory, with predictions verified to 12 decimal places. There are many reasons to love Maxwell’s equations. And with Mathematica 9′s new vector analysis functionality, exploring them has never been easier.

So what exactly are Maxwell’s equations? They are a set of four partial differential equations that describe how electric and magnetic fields respond to charges, currents, and each other. In 1861, James Clerk Maxwell corrected and combined four disparate equations that had been known in one form or another in order to create a comprehensive theory of electromagnetism. In natural Lorentz-Heaviside units, they take the following form.

In the above, ℰ is the electric field, ℬ is the magnetic field, ρ is the charge density, and j is the current density. The operation is called the divergence of v and is a measure of whether the field in a region is pointing away from a point (a positive number), in toward the point (a negative number), or uniformly across it (zero). Finally, is the curl of v and is a measure of how quickly and in what direction the field is swirling about a particular point. Thus, while Maxwell’s equations look complicated—and have many interesting mathematical properties—they can be summarized as follows:

1) Electric fields point away from positive charges and toward negative charges.

2) Magnetic fields never point in or out of a single location, but only point uniformly in the same direction or form closed loops.

3) Electric fields swirl when there is a magnetic field changing in time.

4) Magnetic fields swirl when there is a time-varying electric field or when an electric current is flowing.

Perhaps the most famous solution of Maxwell’s equations is the Coulomb field, which is the electric field and magnetic field of a stationary point with charge q. In spherical coordinate {r,θ,φ} these have the form

We can verify that these are in fact a solution to Maxwell’s equation using the new Div and Curl functions. These take the field to be differentiated, the coordinates, and (optionally) a coordinate system. Since these solutions are expressed in spherical coordinates, the syntax is

Using the new function TransformedField, we can convert the electric field to Cartesian coordinates {x,y,z}.

There is no need to convert the other fields, since they are all zero and therefore will remain zero in all coordinate systems. Still, we can verify that &#8496Cartesian satisfies Maxwell’s equations in the new coordinate systems.

Here is a visualization of the electric field in which the charge has been set to 4π. Since this charge is positive, the field is pointing away from the charge at the center. Also, the magnitude of the field decreases rapidly with distance from the center because it is proportional to .

Mathematica supports many more coordinate systems than just the basic spherical and Cartesian coordinates. All of them can be found using the function CoordinateChartData. In three dimensions, 14 coordinate systems are supported.

One of the most important discoveries Maxwell made was that electric and magnetic fields can form wave configurations which travel from one place to another. The discovery of electromagnetic waves has led to radio, television, radar, and countless other technologies. The derivation is as elegant as it is short. Assuming we are in vacuum (ρ==0 and j==0), we take the curl of both sides of the third Maxwell equation, yielding

Using the following vector identity on the left-hand side

and interchanging the order of operations and substituting in the fourth Maxwell equation on the left-hand side yields

But by the first Maxwell equation, given the vacuum condition, the first term in the equation is also zero. Rearranging produces the famed wave equation for the electric field.

Performing a similar analysis of the fourth Maxwell equation produces the same wave equation of ℬ.

One of the simplest solutions to these wave equations is the plane-wave solution given by

This solution represents a uniform beam of light traveling in a single direction. Of course, the solution obeys Maxwell’s equations.

It also obeys the specific wave equations derived above.

Plane wave solutions model electromagnetic waves that are far from the source, as compared with the wavelength of the wave or the size of the source, traveling over relatively short distances. If we plot intensity ℐ = |ℰxℬ| as a function of position and let time vary, we see a wave pattern moving to the right.

Another simple but important approximate solution to Maxwell’s equation is the dipole radiation field, given in spherical coordinates by

As these are approximate solutions, they do not exactly satisfy Maxwell’s equations. They do satisfy the second and third equations—the so-called homogeneous equations that have no charges or currents in them.

However, because terms containing have been dropped from the solutions, ℰdipole and ℬdipole only satisfy the other Maxwell equations if terms proportional to are ignored.

These approximate solutions are useful because they model the electric field far from a radiating source, for example a radio transmitter. Since r is assumed to be large, the terms proportional to are negligible compared with the terms that are kept. Again, we use the intensity to visualize the field. In spherical coordinates, we have the intensity as

Since the intensity does not depend on azimuthal angle φ, it does not matter which direction in the xy plane we consider. We therefore convert to Cartesian coordinates and restrict to the xz plane (y==0).

We can now make a density plot in the xz plane. Bright color corresponds to high intensity and dark color to low intensity. You can see that as the distance from the source increases, the intensity falls off. Moreover, as time increases, new crests of high intensity travel outward from the center and slowly decrease in intensity.

The solutions discussed above are some of the simplest known solutions of Maxwell’s equations. There is no completely general solution in terms of known functions, so a variety of different techniques for solving the equations in different applications have been developed. In the case of time-independent fields, it is common to use potential functions. For example, we can write ℰ = -∇V (which is always possible in this case, since ∇xℰ == 0 by the third Maxwell equation), and then focus on the first equation to get

This is Poisson’s equation, or, for ρ == 0, Laplace’s equation. In cylindrical coordinates, it takes the form

In the case of cylindrical symmetry, when V and ρ depend only on r, DSolve can return an answer for any density function.

For time-dependent situations, it is common to use Green’s functions, which are essentially solutions for a point particle in a form that can be integrated to give the solution for an arbitrary charge distribution. For more complicated situations, it may be necessary to use numerical methods as embodied by NDSolve. But whether exploring Maxwell’s equations symbolically, numerically, or visually, Mathematica has the tools for the job.

Posted in: Mathematics

 If you’re a fan of Maxwell’s Equations, you can’t miss this great song about Ampère’s law http://www.haverford.edu/physics/songs/ampere.htm Posted by Carlo    September 20, 2013 at 4:38 am
 Hi Itai I too think Maxwell’s equations are wonderful in many ways. In my Honours thesis I started with them in vector form, and rewrote them in tensor notation as a preliminary to looking at gravitational waves – I liked tensor calculus. I though that somewhere I once read that Einstein claimed that in solving a mathematics problem, a good notation is half the battle. That was tensor calculus for him, and the best way to express GR. Thanks for a great post. Posted by Barrie Stokes    September 25, 2013 at 12:56 am
 Sorry to be a bit of a stickler, but I really prefer that we refer to those four equations as Heaviside’s reformulation of Maxwell’s equations. I understand that Maxwell’s original equations numbered quite a bit more than four, and Oliver Heaviside used the div and curl operators (an innovation of his) to trim them down to something that fits on a tee-shirt. He was a sharp gent, and often overlooked. I’d like to mention him here. Posted by SteveofCaley    October 30, 2013 at 5:43 am
 I’m all for giving Heaviside his props. Among his many contributions is also the epynomous Heaviside step function. And you are of course correct that Maxwell never wrote his equations using vector notation; that was one of Heaviside’s advances. But I think it is perfectly acceptable to call these Maxwell’s equations, just as we often times call the tensor and differential form versions of these equations “Maxwell’s equations”. The mathematical and physical content is largely the same, even if the machinery has changed. Posted by Itai Seggev    October 31, 2013 at 1:57 pm
 Hi Itai, Thanks for sharing. I stumbled upon your blog a couple of days ago. I have a question regarding the wave equation you mentioned. This equation is listed in many books with (1/c^2) , which is missing in the equation you worked with, yet the results are all correct. The answer may be trivial, but it would be kind of you if you explain it to me. Regards Saf Posted by Saf    March 19, 2014 at 9:18 am
 Hi Saf. I’m glad you enjoyed it. The answer to your question is hidden in the sentence right above the equations, where it says they are in “natural, Lorentz-Heaviside units”. The word natural means I have used units in which the fundamental constant of the equations, in the case the speed of light c, is equal to one and is therefore omitted. Incidentally, the Lorentz-Heaviside part means that Gauss’s law takes the form div E = rho, rather than either either div E = rho / epsilon_0 (SI units) or div E = 4 Pi rho (CGS units). Posted by Itai Seggev    April 8, 2014 at 1:02 am
 Thanks for the answer. Posted by saf    June 25, 2014 at 2:25 am
 Dear Itai: I need your advice and help. I have some science idea which must be checked by numerical solution of Maxwell equations. I mean electromagnetic waves, laser beam which is very like to the picture (animation) presented in this your site. a) I am interested in vector solutions (more simple problem state should be discussed). b) It would be desirable to have 3D solution (more simple variant should be discussed) c) Beam propagates in vacuum but meets some simple (in form) absorbed obstacle. It can be presented as boundary conditions (zero field on the obstacle surface). d) This problem must be solved only by wave approach (Maxwell, wave equation…) but not by ray optics. I am ready to buy the available program or pay for solving such problem. Posted by Vladimir    October 4, 2014 at 2:31 pm
 Hi Itai, On the first sight, this note seems very amazing. However if you think twice, the conclusion from some computation/derivation is very confusion. For example the computation/derivation in your Coulomb field, charge exists inside radius r (assume charge volume is much smaller than r), but your divergence is 0. This really confuses me. So I pull up an electromagnetic textbook (Introduction to Electrodynamics by Griffiths) from its equation 1.79 and 2.13 I find out why it is so confusing: because Maxwell’s first equation (Gauss’s law) is described radius r of all value, not just one value. The critical part is when r is on the same size as charge, where the divergence won’t be 0. This shows that since you didn’t define charge density precisely, instead just use totally charge, you won’t have enough information to solve the problem of divergence of electrical field. (Or equivalently, electric field can never be q / (4*Pi*r^2) for all r, when r is the same order as charge, q will change as well.) Posted by DT    March 3, 2015 at 8:13 am
 This example assumes a point charge at the origin is the source of the Coulomb electric field. That means the origin is a singularity, with infinite charge density. The differential form of Maxwell’s equations cannot be evaluated in a meaningful way at a singular point. The equations are valid everywhere else. Posted by Ralph Dratman    June 10, 2015 at 12:06 am