Multipole magnet

Multipole magnets are magnets built from multiple individual magnets, typically used to control beams of charged particles. Each type of magnet serves a particular purpose.
Magnetic field equations.
The magnetic field of an ideal multipole magnet in an accelerator is typically modeled as having no (or a constant) component parallel to the nominal beam direction (formula_1 direction)
and the transverse components can be written as complex numbers:
formula_2
where formula_3 and formula_4 are the coordinates in the plane transverse to the nominal beam direction. formula_5 is a complex number specifying the orientation and strength of the magnetic field. formula_6 and formula_7 are the components of the magnetic field in the corresponding directions. Fields with a real formula_5 are called 'normal' while fields with formula_5 purely imaginary are called 'skewed'.
Stored energy equation.
For an electromagnet with a cylindrical bore, producing a pure multipole field of order formula_10, the stored magnetic energy is:
formula_11
Here, formula_12 is the permeability of free space, formula_13 is the effective length of the magnet (the length of the magnet, including the fringing fields), formula_14 is the number of turns in one of the coils (such that the entire device has formula_15 turns), and formula_16 is the current flowing in the coils. Formulating the energy in terms of formula_17 can be useful, since the magnitude of the field and the bore radius do not need to be measured. 
Note that for a non-electromagnet, this equation still holds if the magnetic excitation can be expressed in units Amperes.
Derivation.
The equation for stored energy in an arbitrary magnetic field is:
formula_18
Here, formula_12 is the permeability of free space, formula_20 is the magnitude of the field, and formula_21 is an infinitesimal element of volume. Now for an electromagnet with a cylindrical bore of radius formula_22, producing a pure multipole field of order formula_10, this integral becomes:
formula_24
Ampere's Law for multipole electromagnets gives the field within the bore as:
formula_25
Here, formula_26 is the radial coordinate. It can be seen that along formula_26 the field of a dipole is constant, the field of a quadrupole magnet is linearly increasing (i.e. has a constant gradient), and the field of a sextupole magnet is parabolically increasing (i.e. has a constant second derivative). Substituting this equation into the previous equation for formula_28 gives:
formula_29
formula_30
formula_31
formula_32
formula_33