The Theoretical Basis of Rectangular Magnet and Coil Design