Solution (source code)

= Solution

For a circular <coil>, use the <Biot-Savart law>
$$
d\mathbf B=\frac{\mu_0 I}{4\pi}\frac{d\boldsymbol\ell\times\mathbf r}{r^3}.
$$
At an axial position $x$, every wire element is at distance $r=\sqrt{a^2+x^2}$. The transverse <magnetic field> contributions cancel by rotational <symmetry>. The axial part of $d\boldsymbol\ell\times\mathbf r$ is $a\,d\ell$, and $\oint d\ell=2\pi a$. Multiplying by the $N$ turns gives
$$
\boxed{\mathbf B(x)=\frac{\mu_0NIa^2}{2(a^2+x^2)^{3/2}}\,\hat{\mathbf x}.}
$$
The <electric current>'s sense fixes the axial direction by the right-hand rule.