In this article, we present a method to design a coil producing an arbitrarily shaped magnetic field by restricting the path of the coil's wires to a regular grid. The solution is then found by a simple least squares minimum. We discuss practical applications, in particular, in the active magnetic field stabilization system of the neutron electric dipole moment experiment at the Paul Scherrer Institute in Villigen, Switzerland. We also publish the software implementation of the method.

Document Type


Publication Date


Notes/Citation Information

Published in American Journal of Physics, v. 86, issue 8, p. 602-608.

© 2018 Author(s)

All article content, except where otherwise noted, is licensed under a Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

Digital Object Identifier (DOI)


Funding Information

This work was supported by the Swiss National Science Foundation under Grant Nos. 200020_162574 and 200020_172639.