Closed-Form Expressions for the Magnetic Fields of Rectangular and Circular Finite-Length Solenoids and Current Loops

Abstract A summary of closed-form expressions for the magnetic fields produced by rectangularand circular-shaped finite-length solenoids and current loops is provided altogether for easy referral. Each expression provides the magnetic field in all space, except locations where a current of infinitesimal thickness is considered to exist. The closed-form expression for the magnetic field of a rectangular-shaped finite-length solenoid is derived using the Biot-Savart law. Closed-form expressions for the magnetic fields of solenoids and current loops can be used to avoid approximations in analytical models and may reduce computation time in computer simulations.

). The closed-form expression presented here for the magnetic field generated by a rectangular finite-length solenoid has not been published previously, to our knowledge.
Closed-form expressions for the magnetic fields of solenoids and current loops have been used for developing analytical models and computer simulations (see, for example, Refs. [6][7][8][9][10][11][12][13][14][15][16]). The expressions presented here are in forms that may simplify analytic or numerical calculations and are readily non-dimensionalized. The expressions for the circular current loop and solenoid cannot be reduced to elementary functions without loss of generality, but the elliptic integrals have well defined properties and relations (see, for example, Ref. [17]).
Furthermore, common forms of the elliptic integrals are available in many numerical algorithm libraries (see, for example, Ref. [18]).

SUMMARY OF CLOSED-FORM EXPRESSIONS
Hereafter, µ 0 is the permeability of free space, I is current in an infinitesimally thin wire that is wound in a rectangular or circular shape around the z axis of a Cartesian coordinate system to form either a single-turn current loop or a multi-turn solenoid, and n is the number of wire turns per unit length of a solenoid. The current I is defined to be positive if current flows in the counterclockwise direction when viewing a current loop or an entire solenoid from a location on the z axis at z > 0.

A. Rectangular Finite-Length Solenoid
For a rectangular finite-length solenoid that is centered at the origin of a Cartesian coordinate system, with coordinates (x, y, z), the magnetic field components are where Here, B 0 = µ 0 In in SI units, 2a x , 2a y , and 2a z are the dimensions of the solenoid in the x, y, and z dimensions, respectively. The magnitude of the magnetic field inside the solenoid in the limit of infinite length, L = 2a z → ∞, is |B 0 |.
A sketch depicting the geometry is shown in Fig. 1. The field magnitude is plotted at the axial center of an example solenoid in Fig. 2 and at one axial edge of the solenoid in Fig. 3. It is found that the field magnitude approaches azimuthal symmetry at z = 0 inside and outside of a square finite-length solenoid in the limit a z a x = a y . It may seem counterintuitive that the contours in Fig. 2 display an apparent azimuthal symmetry. Such an apparent symmetry occurs near z = 0 inside of a long square solenoid, because |B x | << |B z | and |B y | << |B z | Here, Θ(x) is the Heaviside step function, which is equal to 1 for x ≥ 0 and equal to 0 for x < 0, and δ(x) is the Dirac delta function. Cartesian coordinates (x s , y s , z s ) with s subscripts refer to source points, and Cartesian coordinates (x, y, z) without subscripts refer to field points.
The x and y components of the magnetic field are or The integrals over z s have the form, where a, b, and c do not depend on the integration variable. Excluding locations where the current flows, the magnetic field components become Both integrals have the same form, or dw Applying to Eqs. (29) and (30) and defining results in the expressions given in Sec. II A.
The z component of the magnetic field is which can be written as The inner integrals have the form, which, when substituted into the preceding expressions, gives The remaining integrals have the form, which, when substituted into B z1 and B z2 , gives the result in Sec. II A. IV.

DISCUSSION AND CONCLUSION
For the models used here for rectangular and circular multi-turn solenoids, the current is considered to flow only in the azimuthal direction, with no current flowing in the z direction.
A real multi-turn solenoid may not have current that flows only in the azimuthal direction.
For example, if a winding begins at one end of the solenoid, the winding may form a helix such that the wire reaches the other end. The effect of current flow in the z direction in a real solenoid may be reduced, for example, by increasing the number of wire turns per unit length n, by having different layers of windings alternate between being a right-handed helix and a left-handed helix, so that the wire is wound back and forth along the length of the real solenoid, and by careful design of the end windings to minimize end effects. However, real multi-turn solenoids and even single-turn magnetic coils will have a current path with finite thickness. In contrast, for all of the models used here for solenoids and current loops, a current of infinitesimal thickness is considered. Additionally, the corners in rectangular current loops and solenoids are modeled here without the finite radius of curvature present in the wire bends of real rectangular magnetic coils.
The closed-form expressions presented here are for idealized cases. The validity of an expression for representing a particular real magnetic coil depends on many factors, including the specifications, tolerances, and materials used in the construction of the coil. To assess the range of validity of a model used here for a solenoid or current loop, when the model is to be used to represent a real magnetic coil, the magnetic field that is calculated with a closed-form expression can be compared to the magnetic field obtained by measurement or by solving the Biot-Savart law numerically. Ideally, such an assessment would be done before using the closed-form expression in an analytical model of a physical system or in a computer simulation (e.g., to reduce computation time). It should also be noted that the use of superpositions of magnetic fields calculated with the closed-form expressions presented here may improve the range of validity of a model that represents a real magnetic coil.
For example, to represent a real solenoid with finite thickness, an improvement over using a single solenoid model with infinitesimal thickness may be to use two nested coaxial solenoids as the model, with a difference in solenoid radius equal to the thickness of the real solenoid.
For all four of the current configurations that were considered here, the associated closedform expressions are exact solutions of the Biot-Savart law and are expected to provide more accurate results than solutions obtained by numerically solving the Biot-Savart law for the same current configuration. A simple relationship that indicates the validity of an expression used for estimating the magnetic field of a representative real magnetic coil is not provided, because many aspects of a real coil can vary widely including but not limited to the number of layers of windings, the wire's pitch angle per layer, the design of the end windings to minimize end effects, the radius of curvature present in the wire bends of rectangular magnetic coils, the wire cross section (e.g., if water cooled), the electrical insulation thickness, the coil dimensions, and the specifications, tolerances, and materials used for the construction of a real magnetic coil. In addition, the validity of an expression used for estimating the magnetic field of a representative real magnetic coil depends on the location in space where the magnetic field is calculated.
In summary, closed-form expressions have been provided for the magnetic fields of rectangular and circular finite-length solenoids and rectangular and circular current loops in Sec. II. Derivations for the closed-form expressions have been provided in Sec. III and Appendixes B to D. Closed-form expressions for the magnetic fields of solenoids and current loops can be used for analytical models (e.g., to avoid approximations) and for computer simulations (e.g., to potentially reduce computation time).

Appendix A: Definitions Used for the Complete Elliptic Integrals
The complete elliptic integrals of the first, second, and third kinds are Relations between various forms of the elliptic integrals, their derivatives, and limiting values are available (see, for example, Ref. [17]).
The current loop is approximated as an infinitesimally thin wire that carries an electrical current and that forms a rectangle. The expressions obtained for the magnetic vector potential and the magnetic field do not apply at the wire, where the current density is infinite.
An expression for the magnetic vector potential A produced by the rectangular current loop is derived by carrying out a closed line integral: Here, dr s is a position differential along the current path, the direction of dr s can be parallel or antiparallel to the current and is to be chosen based on the orientation of a coordinate system, R = |r − r s |, where r is the vector position of a "field" point at a location where the magnetic vector potential is to be evaluated, and r s is the vector position of a "source" point at a location along the current path.
A Cartesian coordinate system is defined such that the origin is located at the geometric center of the rectangular current loop, the z axis is normal to the plane in which the rectangular current loop resides, and the x axis and the y axis are each parallel to two sides of the rectangular current loop. Each side parallel to the x axis has length 2a x , and each side parallel to the y axis has length 2a y . The Cartesian coordinate system has unit vectors denotedî,ĵ,k. Cartesian coordinates (x, y, z) without subscripts refer to field points.
Cartesian coordinates (x s , y s , z s ) with s subscripts refer to source points. The expression for The integral used to determine the magnetic vector potential is separated into four sequential line integrals, one integral for each straight segment of the rectangular current loop. The sequential line integrals are carried out in the counterclockwise direction when viewing the z = 0 plane from a location at z > 0. The result is written as The magnetic vector potential is written in terms of Cartesian components as A = The nonzero components are written as where γ(1) = 1 and γ(2) = −1, or, equivalently, γ(m) = −(−1) m with m restricted to having a value of either 1 or 2. The magnetic vector potential is defined to within an arbitrary additive function so long as the curl of the function equals zero. Each integral has the same form, and the associated indefinite integral is evaluated to within an additive constant. The result for the first integral is written as where c is a constant. A similar result applies for the second integral. The nonzero components of the magnetic vector potential are The magnetic field of a rectangular current loop is evaluated from the magnetic vector potential using B = ∇ × A. The result is given in Sec. II C.

Appendix C: Circular Finite-Length Solenoid
A wire carries an electrical current and is wound to form a finite-length solenoid of constant radius. The wire and solenoid wall are each approximated as being infinitesimally thin. The expressions obtained for the magnetic vector potential and the magnetic field do not apply at the wire, where the current density is infinite. An expression for the magnetic vector potential A produced by the finite-length solenoid is derived by carrying out a surface integral: Here, dS s is a surface differential along the current path, the direction of dS s is either parallel or antiparallel to the current and is to be chosen based on the orientation of a coordinate system, I is the current carried by the wire, I is positive if the current is in the same direction as dS s , I is negative if the current is opposite to the direction of dS s , n is the number of wire turns per unit length of the solenoid, µ 0 is the permeability of free space, and R = |r − r s |, where r is the vector position of a "field" point at a location where the magnetic vector potential is to be evaluated, and r s is the vector position of a "source" point at a location along the current path.
Three coordinate systems are defined, consisting of a Cartesian coordinate system and two cylindrical coordinate systems. For each coordinate system, the origin is located at the geometric center of the finite-length solenoid, and the z axis is coincident with the axis of symmetry of the finite-length solenoid. The Cartesian coordinate system has unit vectors denotedî,ĵ,k, and the two cylindrical coordinate systems have unit vectors denotedr,θ,k andr s ,θ s ,k, respectively. All three unit vectors parallel to the z axis point in the same direction, and the same symbolk is used to denote each of them. Different symbols are used to denote radial and azimuthal unit vectors associated with field and source vectors.
Cartesian coordinates (x, y, z) and cylindrical coordinates (r, θ, z) without subscripts refer to field points. Cartesian coordinates (x s , y s , z s ) and cylindrical coordinates (r s , θ s , z s ) with s subscripts refer to source points. The usual orientation is used for the cylindrical coordinate systems relative to the Cartesian coordinate system. For example, the azimuthal angle θ is zero for a field point on the y = 0 plane with x > 0, and the azimuthal angle increases according to the right-hand rule. Therefore, the following relations apply: x s = r s cos θ s , y s = r s sin θ s .
The current path forms a shell of constant radius, where a denotes the radius of the finite-length solenoid. Because of the cylindrical symmetry of the configuration, the magnetic vector potential expressed in terms of cylindrical coordinates (r, θ, z) will not be a function of θ, and the magnetic vector potential is evaluated at The expression for R is The source unit vectors perpendicular tok are related to Cartesian unit vectors bŷ r s = cos θ sî + sin θ sĵ ,θ s = − sin θ sî + cos θ sĵ . (C7) Using conventional practice, the surface differential for the source is written as dS s = ±r s dr s dθ sk ± r s dθ s dz srs ± dz s dr sθs . With r s = a, the differential of r s is zero, dr s = 0, and dS s = ±adθ s dz srs . By following conventional practice, the direction of the surface differential for the source is in the ±r s direction, which is normal to the differential surface area. In the present work, the direction of the surface differential is chosen to beθ s instead, dS s = adθ s dz sθs . The current-carrying wire is considered to be wound in the azimuthal direction, and I is positive or negative if the current is in theθ s or −θ s direction, respectively.
The source surface differential in cylindrical coordinates is dS s = a dθ s dz sθs = −a sin θ s dθ s dz sî + a cos θ s dθ s dz sĵ .
The magnetic vector potential is where L is the length of the solenoid. The integrand of the first inner integral is an odd function of the integration variable θ s , and the first inner integral equals zero. The integrand of the second inner integral is an even function of the integration variable θ s , and the second inner integral can be evaluated by integrating over positive values of the integration variable and multiplying the integral by a factor of two. Also, at θ = 0, the equalityθ =ĵ applies.
A(r, θ, z)| θ=0 = µ 0 Ina 2π In terms of cylindrical components, the magnetic vector potential is written as A = A rr + A θθ + A zk . The system is cylindrically symmetric, and the finding A r = A z = 0 at θ = 0 also applies for nonzero values of θ. The only nonzero component of the magnetic vector potential is The integral over z s is evaluated by carrying out a change of the integration variable: Carrying out the change of the integration variable yields, The magnetic field of a finite-length solenoid is evaluated from the magnetic vector potential, A = A θ (r, θ, z)θ, using B = ∇ × A. The magnetic vector potential is defined to within an arbitrary additive function so long as the curl of the function equals zero. In terms of cylindrical components, the magnetic field is written as The radial component of the magnetic field is evaluated as Evaluating the partial derivative and reversing the order of integration yields, The quantity, a 2 +r 2 −2ar cos θ s , is positive, because the smallest value occurs when cos θ s = 1, for which a 2 + r 2 − 2ar = (a − r) 2 . Evaluation of the inner integral yields where 1 √ a 2 + r 2 + ζ 2 − 2ar cos θ s ζ + ζ − = 1 a 2 + r 2 + ζ 2 + − 2ar cos θ s − 1 More generally, the following notation is used hereafter: Here, f (x) is a real function of a real parameter x, which has values x − and x + , with x + > x − . With such notation, the radial component of the magnetic field is equivalently written as Integration gives (see, for example, Ref. [1]) where and the complete elliptic integrals of the first and second kinds are given in Appendix A.
An expression for B z (r, θ, z) is now obtained starting with Eq. (C12). Note from Eq. (C15) that there are two terms to evaluate. Equation (C12) with the order of integration reversed The inner integral is simplified further by carrying out a second change of integration vari- Evaluation yields Let u(θ s ) = ln Integration by parts gives Equation (C30) divided by r is the first term on the right in Eq. (C15) and is to be added to another integral that represents the second term on the right in Eq. (C15). Equation

(C26) is written equivalently as
The second term on the right in Eq. (C15) is ζ(a cos θ s − r) (a 2 + r 2 − 2ar cos θ s ) √ ζ 2 + a 2 + r 2 − 2ar cos θ s + r − a cos θ s a 2 + r 2 − 2ar cos θ s cos θ s dθ s where r − a cos θ s a 2 + r 2 − 2ar cos θ s has been used due to having no ζ dependence. An equivalent expression is geometric center of the circular current loop, and the z axis is normal to the plane in which the current loop resides. The Cartesian coordinate system has unit vectors denotedî,ĵ,k, and the two cylindrical coordinate systems have unit vectors denotedr,θ,k andr s ,θ s ,k, respectively. All three unit vectors parallel to the z axis are parallel with one another, and the same symbol is used to denote each of them. Different symbols are used to denote radial and azimuthal unit vectors associated with field and source vectors. Cartesian coordinates (x, y, z) and cylindrical coordinates (r, θ, z) without subscripts refer to field points. Cartesian coordinates (x s , y s , z s ) and cylindrical coordinates (r s , θ s , z s ) with s subscripts refer to source points. The usual orientation is used for the cylindrical coordinate systems relative to the Cartesian coordinate system. For example, the azimuthal angle θ is zero for a field point on the y = 0 plane with x > 0, and the azimuthal angle increases according to the right-hand rule. Therefore, the following relations apply: x s = r s cos θ s , y s = r s sin θ s .
The current path forms a circle, and two cylindrical coordinates are constants, Here, a denotes the radius of the circular current loop. Because of the cylindrical symmetry of the configuration, the magnetic vector potential expressed in terms of cylindrical coordinates (r, θ, z) will not be a function of θ, and the magnetic vector potential is evaluated at The expression for R is The source unit vectors perpendicular tok are related to Cartesian unit vectors bŷ r s = cos θ sî + sin θ sĵ ,θ s = − sin θ sî + cos θ sĵ .

(D9)
The integrand of the first integral is an odd function of the integration variable, and the first integral equals zero. The integrand of the second integral is an even function of the integration variable, and the second integral can be evaluated by integrating over positive values of the integration variable and multiplying the integral by a factor of two. Also, at θ = 0, the equalityθ =ĵ applies.
In terms of cylindrical components, the magnetic vector potential is written as A = A rr + A θθ + A zk . The system is cylindrically symmetric, and the finding A r = A z = 0 at θ = 0 also applies for nonzero values of θ. The only nonzero component of the magnetic vector potential is A θ (r, θ, z) = µ 0 Ia 2π π 0 cos θ s dθ s √ r 2 + a 2 + z 2 − 2ra cos θ s .
For given values of r and a, the smallest value of the quantity, r 2 + a 2 + z 2 − 2ra cos θ s , is greater than or equal to zero, because the smallest value occurs when cos θ s = 1 and z = 0 for which r 2 + a 2 − 2ra = (a − r) 2 . The integral is evaluated to be A θ (r, θ, z) = µ 0 I 2πr   (a 2 + r 2 + z 2 ) K (m) (a + r) 2 + z 2 − (a + r) 2 + z 2 E (m) where m = 4ar (a + r) 2 + z 2 , and the complete elliptic integrals of the first and second kinds are given in Appendix A.
The magnetic vector potential is defined to within an arbitrary additive function so long as the curl of the function equals zero.
The magnetic field of a circular current loop is evaluated from the magnetic vector potential, A = A θ (r, θ, z)θ, using B = ∇ × A. In terms of cylindrical components, the magnetic field is written as B = B rr + B θθ + B zk . The cylindrical components are (see, for example,

Ref. [3])
B r (r, θ, z) = µ 0 I 2π z r 1 (a + r) 2 + z 2 a 2 + r 2 + z 2 (a − r) 2 + z 2 E (m) − K (m) , Data sharing is not applicable to this article as no new data were created or analyzed in this study.