I've just started a project, trying to do simulation of electrodynamics using the well-known Maxwell equations: $$ \nabla \cdot \mathbf E = \rho \\ \; \\ \nabla \cdot \mathbf B = 0 \\ \; \\ \nabla \times \mathbf E = -\frac{\partial \mathbf B}{\partial t} \\ \; \\ \nabla \times \mathbf B = \mathbf J + \frac{\partial \mathbf E}{\partial t} \\ \; \\ $$ Once I setted up the project, I was going to see how could I simulate the equations, but they are coupled. For example: $$ \nabla \cdot \mathbf E = \frac{\partial E^1}{\partial x_1} + \frac{\partial E^2}{\partial x_2} + \frac{\partial E^3}{\partial x_3} = \rho $$ This equations depends on $E^1$, $E^2$ and $E^3$, which we have to find with the others equations. It is possible to write individual equations for each field component, to then integrate numerically? Is there any other better method? I'm new to all of this, so any help would be appreciated.

Note: I would use C as the language of the project, if that could help.

  • $\begingroup$ Why not use something others have already developed: dealii.org/developer/doxygen/deal.II/group__vector__valued.html $\endgroup$ Commented Jun 12, 2023 at 15:42
  • $\begingroup$ And this en.wikipedia.org/wiki/Jefimenko%27s_equations $\endgroup$
    – mmikkelsen
    Commented Jun 12, 2023 at 16:41
  • 2
    $\begingroup$ To add a bit more context to Wolfgang's comment, the numerical simulation of PDEs is one of the most well-studied and widely practiced applications of numerical analysis, functional analysis, and scientific computing in the last century. As in the analysis of PDEs, different equations often require different tools to simulate. There are a wide variety of frameworks, methods, and software packages out there and for nontrivial problems. It is almost certainly a better use of your time to use an existing library then go from there, especially in a low-level language like C. $\endgroup$
    – whpowell96
    Commented Jun 12, 2023 at 23:41

1 Answer 1


The full set of Maxwell's equations is actually over-constrained. You have a coupled system of 8 PDEs, but only 6 scalar components to solve for.

There are a few ways to resolve this:

  1. Ignore Gauss's Laws and solve just Ampere's Law and Faraday's Law. This produces a set of hyperbolic PDEs, of which there are many methods for solving these (finite difference, finite volume, finite elements, etc.). This method works well if you're interested in the time evolution and wave propagation behavior of electromagnetic fields. Because you're ignoring Gauss's laws there is the potential for divergence errors to crop up (either as a result of initial conditions or the numerical discretization). Different discretizations can mitigate this (see: Yee Grids or Nedelec elements).
  2. Re-write Gauss's Law for electrostatics as Poisson's equation and solve for the scalar potential, ignoring all the other equations. Note that the approximation $$ \vec{E} = - \nabla \phi $$ is only a good approximation for slowly varying $\vec{E}$. As a result this approach is suitable if you're interested in the slowly varying (near electrostatic/megnetostatic) behavior of electromagnetic fields. In this case you aren't really solving for the magnetic field at all, only the electric field. This is an elliptic PDE and methods for solving Poisson's equation are readily available.
  3. Introduce extra scalar variables which represent the divergence error in each field. This eliminates the over-constrained nature, and gives you numerical tools for mitigating any divergence errors. This is the most complex and computationally expensive method as you potentially might end up with a mixed hyperbolic/parabolic PDE system. Look up "divergence cleaning methods" for more information on these type of methods.

There are also boundary element methods which try to get around directly solving Maxwell's equations but still can be used to solve for EM field behavior. I'll leave these out of the scope of this answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.