Exploring the magnetic field of Helmholtz and Maxwell coils: a computer-based approach exploiting the superposition principle

Teaching magnetism is one of the most challenging topics at undergraduate level in programmes with scientific background. A basic course includes the description of the magnetic interaction along with empirical results such as the Biot-Savart law's. However, evaluating the magnetic field due to certain current carrying system at any point in space is not an easy task, especially for points in space where symmetry arguments cannot be applied. In this paper we study the magnetic field produced by both Helmholtz and Maxwell coils at all points in space by using a hybrid methodology that combines the superposition principle and an analytical result. We implement a computational approach, that is based on iterating $n$ times the magnetic field produced by a finite current-carrying wire, to evaluate the magnetic field at any point in space for coils arrangements without using advanced calculus. This methodology helps teachers and students to explore the field due to systems with different levels of complexity, combining analytical and computational skills to visualize and analyse the magnetic field. After our analysis, we show that this is an useful approach to emphasize fundamental concepts and mitigate some of the issues that arise when evaluating the magnetic field for systems proposed in introductory physics textbooks.


Introduction
The electromagnetic theory is one of the fundamental pillars of the scientific training at undergraduate level of physicists and engineers.Within the wide variety of topics considered in the course syllabus, magnetism is one of the most fascinating both in science and engineering due to its applications in so many diverse areas, in industry and in academia as well [1].However, from an educational point of view, this is also a non-easy topic to teach or to learn [2,3], what has motivated different approaches focused on the effectiveness of the methodologies to avoid possible misconceptions.On the other hand, the continuous development of computational tools has completely revolutionized education, providing a powerful way to visualise and analyse 'invisible phenomena' such as the magnetic field, making it a much easier problem mathematically than ever before without requiring experimental equipment [4][5][6][7][8].
Evaluating the magnetic field, at some point in space, produced by electric current elements is one of the aims in introductory courses.It implies that students must develop extended mathematical skills taking care of empirical relations such as the Biot-Savart law.To help students comprehend this topic better, we study from a computational approach and using the superposition principle, the magnetic field created by two systems: the Helmholtz and the Maxwell coils.The paper is organized as follows: in Section 2 we derive the analytical expressions of the magnetic field produced by both coil configurations in all points of space, then we introduce our approach considering the field created by the superposition of n finite wires as alternative to the analytical solution.In Section 3 we present the computational implementation and the numerical analysis.The results about our methodology and its impact in teaching the magnetic field for the coil configurations considered are discussed in Section 4. Finally, we draw our conclusions in Section 5.

Magnetic Field Due to Coil Configurations
The Biot-Savart law summarizes in a very clever way the experimental results on the force exerted by an electric current on a nearby magnet.Originally, these results were presented in terms of measurements of the torque on a magnet near a long wire, but were later analyzed in terms of the magnetic field produced by each element of the current [9].The Biot-Savart law describes the magnetic field dB at any point in space due to an element dl of a current-carrying wire as follows: where I is the electric current, µ 0 is the vacuum permeability and êr is an unit vector along r that points from dl to any point in space.Since evaluating the magnetic field at each point in space depends on the distance from the electric source, an analytical expression will highly depend on the geometry of the current-carrying wire and hence on how complicated is the integral of Eq.( 1).In this context, a common exercise consists of evaluating the magnetic field produced by current carrying circular loop at one point on its axis.This is easily solved, as many textbooks presented, by using i) the Biot-Savart law, ii) the right-hand rule and iii) symmetry arguments.However, evaluating the magnetic field on off-axis points of the ring, turns the problem into advanced and out of the goals of the course because of its difficulty level.In addition, the situation becomes more complex when the configuration involves more than one loop, such as in the case of the Helmholtz and Maxwell coils.The latter is not commonly found in traditional textbooks, while the Helmholtz coils are widely discussed.
The arrangement of coils is usually introduced in the textbook section on sources of magnetic field because of its variety of applications (for a detailed description see e.g.[10][11][12][13][14][15][16]).In fact, they play an important role in industry, medical equipment and material characterization, since they can produce an uniform magnetic field in a small region of space.Specifically the Helmholtz coils are the most simple and widely used system to study the magnetic properties of matter, canceling Earths's magnetic field and in laser cooling and trapping, where a field with a uniform gradient is desired.In what follows, we focus on the mathematical description of the coil configurations and the computational approach.

The Helmholtz and Maxwell coils
The superposition principle states that the field created by different sources simply added together as vectors, thus the total field of a coil arrangement can be expressed as the superposition of the field created by each one of the coils.First let's focus on the magnetic field created by a single loop, a circular wire of radius R located in the xy plane that carries a steady current I as shown in Fig. 1a.In principle, it is relatively simple to evaluate analytically the magnetic field at any point in space since it is reduced to integrate Eq. (1), however it can be problematic for points in space where it is not possible to use symmetry arguments, even if an appropriate coordinate system is chosen.This is a common example/exercise that appears in many introductory textbooks including some simplifications (see e.g.[17][18][19][20]).In the most general case, it is possible to show that after some manipulations of the Biot-Savart law, the magnetic field created by a circular loop in Cartesian coordinates at any point in space is given by [20][21][22][23]: where Here K(k 2 ) and E(k 2 ) represent elliptic integrals of first and second kind respectively.As mentioned before, even if the problem is solved in cylindrical coordinates, elliptical integrals appear, being the azimuthal component the only one that vanishes because of symmetry.The fact that math tools from advanced calculus are needed to completely solve the problem, is perhaps the reason why many introductory textbooks only present a very simplified version of the real system, i.e. asking for the magnetic field on an axial point at certain distance from the loop center instead of all points in space.For this particular case, the field expression is simply given by: These expressions are useful to evaluate the magnetic field created by coil configurations.Specifically, the Helmholtz coils consist of two circular coils of radius R, each with N turns, that are perpendicular to a common axis as shown in Fig. 1b.They carry equal steady currents I in the same direction such that their axial fields are added to each other and the coil centers are separated by a distance equal to their radius.Setting the origin of the coordinate system in the middle point of the coils, as shown in Fig. 1b, instead of the center of one them, the magnetic field on the z axis is given by: An important feature of Helmholtz coils is that the resultant magnetic field in the region between the coils is very uniform.This can be shown easily, since dB/dz and d 2 B/dz 2 are both zero at the point midway between the  coils, thus we may then conclude that the magnetic field in that small region is uniform.A rigorous analysis on the the magnetic field homogeneity and their expression for several coil arrangements, including the Helmholtz ones, can be found in [24].
On the other hand, the Maxwell coils consist of an arrangement of three circular and coaxial coils separated by certain ratios as illustrated in Fig. 1c.Following the original Maxwell's design [25], the central coil has a radius R while the two side coils have a radius 4 7 R, being located on either side of the main coil at distance 3 7 R from its plane.As in the Helmholtz coils, in the Maxwell's arrangement all the three currents have the same direction, however in this case the electric current follows the ratio I ≡ I central = 49 64 I outer .Under these parameters, the total magnetic field for points located on the axis of the coils is given by the following expression: Fig. 2 shows the magnetic field intensity evaluated at points along z-axis created by both the individual coils and the entire system of the Helmholtz and Maxwell arrangements.For illustration purposes we used the following parameters to evaluate Eqs. ( 6) and (7) for the Helmholtz coils and keeping the same parameters for the central coil of the Maxwell arrangement: R = 1 m, N = 10, I = 10 A and z ∈ [−1.5, 1.5] with origin of coordinates in the middle point of the coaxial axis of each system.For these set of parameters the total magnetic field produced by the Maxwell coils is bigger than the produced by the Helmholtz ones, moreover in Fig. 2 we can appreciate that the system with three coils is more efficient producing an almost uniform distributed magnetic field in the region near the center.These results are only valid for the z axis since Eqs.( 6) and ( 7) come from simplifying the general expression of a loop by setting x = 0 and y = 0 in Eq. ( 4).A more realistic case includes the evaluation of the magnetic field at all points in space, which means that elliptical integrals must be used, however this is not usually commented in textbooks, not even as a warning note or as a suggested advanced exercise.In next section we show how the magnetic field produced by coil arrangements can be evaluated in all points in space using basic mathematical tools that students have within reach, instead of introducing elliptical integrals.This approach is based on the field expression for a finite wire and the superposition principle, moreover it provides an excellent scenario to complement with computational tools.

The n-wire approach
In order to evaluate the magnetic field produced by a loop in all space avoiding elliptical integrals, we approximate the geometry of a loop as a regular n-sides polygon.Thus the magnetic field expression is reduced to the superposition of the field produced by n finite wires carrying the same electric current, which is a much simpler problem to solve in the three-dimensional space.The magnetic field due to a finite wire is one of the basic examples introduced in electromagnetism courses, this approximation allows to explore the full solution after applying the Biot-Savart law without loss of generality by exploiting the superposition principle.Moreover, this approach has been explored for several configurations, see e.g.[26], providing a simple evaluation of the field.This has the advantage of being easy to implement numerically since the method iterates a simple geometry to obtain a complex one, keeping the physical properties intact.As it is well known, for a thin and straight wire carrying a current I placed along the z-axis, as shown in Fig. 3, the magnetic field at an arbitrary point P is given by: and j = {A, B}. (8) where cylindrical coordinates have been used for simplicity to map the three-dimensional space, taking advantage of the fact that dl and r are located in the same plain.Consequently, the magnetic field is always oriented along êϕ for each point P , i.e, following concentric circle trajectories regardless of the segment size.The Eq. ( 8) gives a general description of the magnetic field for a current-carrying wire of finite length L, however, for the computational implementation it is useful to express it in Cartesian coordinates considering that the wire can be oriented in any direction.Using the law of cosines and vector decomposition, the magnitude of the magnetic field for an arbitrary located wire can be re-written as [27]: On the other hand, the field direction can be obtained by projecting êϕ along the Cartesian coordinates.From the geometrical construction of Fig. 3(left), and without lost of generality for an arbitrary located wire, the field orientation can be written as follows: This expression can be simplified as: where , the Cartesian components of the magnetic field due to a finite wire, at any point in space are given by: To illustrate the idea behind the n-wire approach, let's consider a n-side regular polygon carrying a current I. Since each side corresponds to a finite wire, then Eq. ( 8) can be used to find B at any point of space.For instance, the field at the center of the polygon can be obtained using Fig. 3, where AB is one of the sides and ρ is the radius of the inscribed circle.The angles θ 2 and θ 1 are derived from the geometrical construction, taking into account that the inner angle of the polygon is given by ∠AOB = 2π/n, thus ∠BOC = π/n.Considering the n wires and using angle properties, the magnitude of the magnetic field in the center of a circular loop of radius r is recovered when n → ∞ and ρ = r, resulting

Numerical analysis
The numerical pipelines to evaluate the magnetic field due to an arbitrarily oriented finite wire have been written in python3 language1 .The implementation consists of defining two functions to i) compute the magnitude of the magnetic field using Eq. ( 9), and ii) evaluate the Cartesian components of the field following Eqs.( 11) and (12).In order to compute the magnetic field produced by a current carrying system at any point in space, it is enough to define its geometry as a superposition of n finite wires and then iterate the routine that evaluates the magnetic field over each wire.In our case, such a system is an arrangement of coils modelled as n side polygons, which satisfy the characteristics of the Helmholtz and Maxwell coils.Figure 4 displays a snippet of the code that implements the n-wire approach to evaluate magnetic field due to a system that can be expressed geometrically as a superposition of n wires.Using this approach, we first evaluated the magnetic field produced by a single circular loop in all points in space within a 3D grid.Fig. 5 illustrates the results for a single loop approximated Then we repeated the analysis for both arrangements: Helmholtz and Maxwell coils, by approximating the circular loops by regular polygons of 80 sides inside a meshgrid of 50 3 points.The first of these systems (Helmholtz coils), consists of two identical coils positioned in parallel to each other in the xz plane with centers aligned with the y-axis.The coil centers are (x 1 , y 1 , z 1 ) = (0.5, 0.0, 0.0) m and (x 2 , y 2 , z 2 ) = (0.5, 1.0, 0.0) m for the first and second coils respectively.As can be noticed both coils are separated by a distance equal to the radius 1 m.The second coil arrangement (Maxwell coils), consists of three coils positioned in parallel to each other in the xz plane with centers aligned along the y-axis.We keep the radius of the middle coil as r = 1 m being centred at (x m , y m , z m ) = (0.5, 0.5, 0.0) m.The radius of the outer coils are r = 4/7m and they centers are located at (x, y, z) = (0.5, r/2 ± 3/7r, 0) m respectively.As can be noticed each coil is apart from each other by 3/7 m.The Fig. 6 shows the behaviour of the magnetic field intensity for both configurations: Helmholtz coils (on the left panels) and Maxwell coils (on the right panels).The magnetic field along axes parallel to the central one in the plane z = 0 is displayed in the upper panels, while the lower panels show B(x, y) as a function of the spatial coordinates in the meshgrid for the plane z = 0.In both plots we can appreciate how the magnetic field changes according to the distance from the central axis of the coils.This representation in slices of B at different x values confirms that the field passes from a relatively uniform region at x = 0.5 m until it reaches the coils position, where the field is very intense as expected.Moreover, at these distances the Maxwell coils provide an even more uniform magnetic field than the Helmholtz coils with a higher intensity at the region 0 y[m] 1.
Figure 7 shows the 2D iso-contours of the magnetic field lines in the z = 0 plane and the 3D iso-surfaces of the norm of the field which covers the magnetic field lines produced by the coil arrangements.The plots on  the left side correspond to the Helmholtz coils while the ones on the right side correspond to the Maxwell coils.From these patterns we observe that a larger volume with strong homogeneity is achieved with the Maxwell coil as predicted.

Discussion
Exploring the magnetic field is a fundamental part of electromagnetism courses where both teacher and students have to face teaching and learning issues.Perhaps, the main issue is related to the fact that evaluating the magnetic field produced by some current carrying systems, at any point in space, require either advanced calculus or an oversimplification of the system.Indeed, many introductory calculus-based electromagnetism textbooks, include symmetry arguments and evaluating the field only at particular points in space (see e.g.[17][18][19]).Here appears a first contradiction, since the concept of magnetic field is introduced referring to a quantity that has a value for every point in space but in the exercises it is evaluated only at specific points or regions.Omitting these key points leads students to use incorrect assumptions and algebra tricks when they try to find the magnetic field in more complex systems where same assumptions cannot be applied.An additional challenge to teach magnetism is related to the mathematical tools required to evaluate the field, since it is not always possible to get an analytic expression for any point in space.
The superposition principle, combined with an analytical expression of the magnetic field of a finite wire, provides a powerful tool to evaluate the field at any point in space created by several current carrying systems.The approach we implemented in this paper allows to mitigate the above mentioned issues, keeping minimal conceptual assumptions with the advantage of modelling more realistic systems and reducing the gap between the concepts and methods when the field is evaluated.In particular we addressed the results for two very well known coil arrangements, the Helmholtz and Maxwell coils, but the methodology is not limited to them.It can be extended to several configurations as long as they can be expressed in terms of n wires.This hybrid methodology provides a mechanism to explore more complex systems that are close to the real ones involving magnetic field calculations.Moreover, simulations and numerical techniques have the advantage of characterise the physical systems considering a wide range of free parameters, exhibiting properties that otherwise are hidden when there are no analytic solutions.It also encourages students to use com-e20200282-8 Exploring the magnetic field of Helmholtz and Maxwell coils putational tools and to create their own systems, which is motivating mainly for engineering students.Finally, the combination of purely mathematical and physical methods (i.e., between the geometrical analysis and the superposition principle in our case study), contributes to the scientific training of future physicists and engineers that must face situations beyond those usually proposed in textbooks.It also gives an additional motivation to students in their learning processes, allowing the electromagnetism course to be influenced by another kind of teaching strategy.

Conclusions
The teaching strategies and resources for physics teaching evolve rapidly with new technologies, specially in topics like magnetism, where physical concepts are not easily assimilable by students.In this paper we have introduced a hybrid method based on superposition principle and computation iterative method to mitigate some of the issues in magnetism teaching.The strategy presented in our work provides a simple method for the calculation of the magnetic fields in several configurations.It also helps understanding the methodology to evaluate the magnetic field due to the Helmholtz and Maxwell coils by using theoretical arguments supported by the Biot-Savart law and numerical techniques.
The coil systems studied here help students to understand the Biot-Savart law as a fundamental structure in the calculation of magnetic fields at all points in space, even in those where symmetry arguments cannot be applied.At the same time, this kind of exercises offer a different point of view than those addressed in most of the textbooks used in higher education on the calculation and applications of magnetic fields.
In a pedagogical context, designing and implementing computational resources of easy access is perhaps a challenge for educators because it requires more time to integrate the strategy.However, today it is known that these resources become a fundamental tool for the consolidation of scientific and technological literacy processes which can potentially reduce the learning curve of students with scientific background.
Extending the methodology proposed here to other topics of electromagnetism can have a positive impact on the way in which fundamental laws of physics are taught such as the Biot-Savart law.In such a case, the traditional teaching techniques based on problem-solving become a learning space where the computational tools are an important factor to achieve meaningful learning from an integrated approach.

Figure 1 :
Figure 1: The three different coil arrangements studied in this paper.

Figure 2 :
Figure 2: The magnetic field evaluated at points along z-axis for two coil arrangements: Helmholtz coils (left panel) and Maxwell coils (right panel).The green, blue and yellow curves show the field produced by the individual coils each system along their coaxial axis.The top red curve is the total magnetic field, illustrating the region of near constant field in the centre.

Figure 3 :
Figure 3: Left panel: a finite straight wire carrying a steady current along z-axis.The magnetic field is evaluated at the point P. Right panel: superposition of n straight wires forming a regular polygonal shaped wire.

Figure 4 :
Figure 4: Python snippet of the n-wire approach to evaluate magnetic fields at any point in space.

Figure 5 :
Figure 5: 2D and 3D projections of the magnetic field created by a circular loop evaluated with the n-wire approach.

Figure 6 :
Figure 6: Upper panels: magnetic field intensity along axes parallel to the central one in the plane z = 0. Lower panels: magnitude of the magnetic field in the plane z = 0 as a function of the spatial coordinates.The plots on the left side correspond to the Helmholtz coils while the ones on the right side correspond to the Maxwell coils.

Figure 7 :
Figure 7: Upper panels: magnetic field intensity and 2D patterns of magnetic field lines in the plane z = 0. Lower panels: 3D patterns and contour surfaces of magnetic field lines.The plots on the left side correspond to the Helmholtz coils while the ones on the right side correspond to the Maxwell coils.