# Finding the electric field surrounding a torus [closed]

I'm trying to use NDSolve to get a notion of the electric field around a uniform torus of density 1 (for simplicity) using Maxwell's equations. I'm running into some trouble.

R = 3;
r = 1;

densityDist[x_, y_, z_] := If[(R - Sqrt[x^2 + y^2])^2 + z^2 < r^2, 1, 0];

Ef[x_, y_, z_] =
Module[{Ef},
Ef[x_, y_, z_] := {Ex[x, y, z], Ey[x, y, z], Ez[x, y, z]};
Ef[x, y, z] /.
NDSolve[
{Div[Ef[x, y, z], {x, y, z}] == densityDist[x, y, z],
Ef[0, 0, 0] == {0, 0, 0}},
Ef[x, y, z],
{x, -6, 6}, {y, -6, 6}, {z, -6, 6}]]


But I get

NDSolve::underdet: There are more dependent variables, {Ex[x, y, z], Ey[x, y, z], Ez[x, y, z]}, than equations, so the system is underdetermined.

Any clues of what other conditions I can put in?

## 2 Answers

What happened to Maxwell's other equations? You're missing $\nabla \times E = 0$ assuming there is no $B$ field.

R = 3;
r = 1;
densityDist[x_, y_, z_] :=
If[(R - Sqrt[x^2 + y^2])^2 + z^2 < r^2, 1, 0];
Ef[x_, y_, z_] = {Ex[x, y, z], Ey[x, y, z], Ez[x, y, z]};


Then we can solve the equations as follows with some particular boundary conditions:

maxwell = {Div[Ef[x, y, z], {x, y, z}] == 0 densityDist[x, y, z]}~ Join~(# == 0 & /@ Curl[Ef[x, y, z], {x, y, z}])[[;; 2]];
NDSolve[maxwell~ Join~{Ex[-10, y, z] == 0, Ey[-10, y, z] == 0, Ez[-10, y, z] == 0}, {Ex, Ey, Ez}, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}]


For this problem however it would be better to take advantage of the symmetries and use spherical coordinates, then you can impose a vanishing boundary conditions at a large value of $r$.

It is easy to see what is happening if you look at what

Div[{Ex[x, y, z], Ey[x, y, z], Ez[x, y, z]}, {x, y, z}] == densityDist[x, y, z]


evaluates to.

R = 3;
r = 1;
densityDist[x_, y_, z_] = Boole[(R - Sqrt[x^2 + y^2])^2 + z^2 < r^2];

Div[{Ex[x, y, z], Ey[x, y, z], Ez[x, y, z]}, {x, y, z}] == densityDist[x, y, z]

Derivative[0, 0, 1][Ez][x, y, z] + Derivative[0, 1, 0][Ey][x, y, z] +
Derivative[1, 0, 0][Ex][x, y, z] ==
Boole[(3 - Sqrt[x^2 + y^2])^2 + z^2 < 1]


Since you have done nothing to tell Mathematica that the partial derivatives are vectors rather than scalars, Mathematica simply sees one equation in thee unknowns. Hence, the error message. You need add equations the make the vector nature of the derivatives clear.