Penning Trap Simulation I'm currently working on a particle tracker and I would like to implement a Penning trap. I think I might have a problem with the field of the electrical quadrupole. My idea was to place 2 dipoles and overlay their electrical fields, so that the tracked particle would be in the middle of the resulting rectangle(similar to the wikipedia article). But the resulting trajectories were not stable and didn't have the right shape. I didn't calculate if the initial conditions would work out so this could be a reason, but I wanted to know if designing it this way would be working out at all?
 A: The underlying problem of your trap design is that two dipoles can't make a quadrupole!
You are probably aware of the multipole expansion of electric (or magnetic) fields. This is where the terms "dipole" and "quadrupole" come from. As a physics student, one often encounters the exterior multipole expansion. This is what you use when there are charges inside some volume, and you want to describe the electric potential (or field) on the outside of (and far away from) that volume with as few and simple terms as possible.
Closeley related, but less well known, is the interior multipole expansion. This is relevant when the charges are placed on the outside of some volume, and you want to describe the potential inside that volume. The interior multipole expansion has surprisingly simple terms when you state it in Cartesian coordinates. (Except for the normalization constants, which are not really standardized and often simply dropped.)
Unfortunately, there is no consensus on how to name or order the terms that come up in the interior multipole expansion. But here is one way to state them, up to the octupolar terms:
$$\Phi(x,y,z) = \sum_{i,|j|\leq i}c_{i,j}\, P_{i,j}(x,y,z) $$
$$ \begin{align}P_{0,0} &= 1 && \nonumber \\
 P_{1,0}  &= z 
 &P_{1,+1} &= x 
 &P_{1,-1} &= y \\
 P_{2,0} &=  -\frac{1}{2}(x^2+y^2)+z^2 
 &P_{2,+1} &= xz 
 &P_{2,-1} &= yz \\
 &&P_{2,+2} &= x^2-y^2 
 &P_{2,-2} &= xy \\
 P_{3,0} &= -\frac{3}{2}(x^2+y^2)z+z^3
 &P_{3,+1} &=  x^3+xy^2-4xz^2
 &P_{3,-1} &=  x^2y+y^3-4yz^2 \\
 &&P_{3,+2} &=  zx^2-zy^2
 &P_{3,-2} &=  xyz \\
 &&P_{3,+3} &=  x^3-3xy^2
 &P_{3,-3} &=  y^3-3x^2y \quad .\end{align}$$
The $P_{0,0}$ term is the monopole term. The corresponding field, given by $\vec{E}_{0,0} = -\vec\nabla P_{0,0} $), evaluates to $0$.
The $P_{1,j}$ terms are the dipole terms. The corresponding fields are
$$\begin{align}
\vec{E}_{1,0} &= -c_{1,0}  \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \\
\vec{E}_{1,1} &= -c_{1,1}  \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix} \\
\vec{E}_{1,-1} &= -c_{1,-1}  \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix}\quad,
\end{align}$$
which are homogenous fields in the $x$, $y$, and $z$ direction.
The $P_{2,j}$ terms are the quadropolar terms. If the magnetic field of your trap points along the $z$-axis, then $P_{2,0}$ gives the electric field that you need for the Penning trap:
$$ \vec{E}_{2,0} = c_{2,0}  \begin{pmatrix} x \\ y \\ -2z \end{pmatrix}\quad . $$
The $P_{3,j}$-terms are the octupolar terms. You hopefully won't need them for your Penning trap (although some traps use them for coupling different modes).
As you can see from the polynomials, or from the corresponding vector fields, there is no way in which you can add two dipoles to make a quadrupole. These terms are all orthogonal to each other.
Exterior and interior multipole expansion are sometimes called "irregular solid harmonics" and "regular solid harmonics", respectively. See this post for a better overview, and for Mathematica code on how to generate the polynomials.
