In this paper, we are interested in finding the optimal shapeof a magnet. The criterion to maximize is the jump of theelectromagnetic field between two different configurations.We prove existence of an optimal shape into a natural classof domains. We introduce a quasi-Newton type algorithm whichmoves the boundary. This method is very efficient to improvean initial shape. We give some numerical results.