Solution (source code)

= Solution

For steady currents in vacuum, the <Biot-Savart law> gives the <magnetic field> by summing oriented current elements. With $\mathbf R=\mathbf r-\mathbf r'$ from the source to the observation point,
$$
\boxed{\mathbf B(\mathbf r)=\frac{\mu_0}{4\pi}\int\frac{\mathbf J(\mathbf r')\times\mathbf R}{R^3}\,d^3r'.}
$$
For a thin wire it becomes $\mathbf B=(\mu_0I/4\pi)\int d\mathbf l'\times\widehat{\mathbf R}/R^2$. The cross product fixes the direction by the right-hand rule. Fields from different steady circuits add by <superposition>; the entire current path, including return wires where relevant, belongs in the calculation.

An infinite straight wire gives circular field lines of magnitude $\boxed{B=\mu_0I/(2\pi s)}$ at perpendicular distance $s$. This follows by integrating the transverse component of each element along the wire. A circular loop of radius $a$ has cancelling transverse components on its axis, leaving
$$
\boxed{B_z(z)=\frac{\mu_0Ia^2}{2(a^2+z^2)^{3/2}},\qquad B_z(0)=\frac{\mu_0I}{2a}.}
$$
Multiple coincident turns multiply the field by their number. Far from the loop this is the field of a magnetic dipole of moment $\boldsymbol\mu=I\pi a^2\widehat{\mathbf n}$. Integrating over many loops gives the approximately uniform interior field $B\simeq\mu_0nI$ of a long <solenoid>, with $n$ turns per unit length. Finite coils have fringing fields, and appropriately spaced coil pairs can produce a more uniform measurement region.

The law is useful for predicting fields of wires and coils where direct symmetry is insufficient, designing electromagnets and estimating stray fields. It is a magnetostatic law: steady charge flow satisfies charge continuity. An instantaneous application to rapidly changing currents neglects propagation and radiation; such problems require the time-dependent <Maxwell's equations> and retarded fields. A quasistatic approximation can be valid when circuit dimensions are small compared with the light-travel distance during the variation timescale.