Put the field point on the x axis, so r = (s, 0, 0). Then B = \frac{\mu_{0}}{4 \pi} \int \frac{( K \times \hat{ ᴫ })}{ ᴫ ^{2}} d a ; d a=R d \phi d z ; K =K \hat{\phi}=K(-\sin \phi \hat{ x }+ \cos \phi \hat{ y }) ;
ᴫ =(s-R \cos \phi) \hat{ x }-R \sin \phi \hat{ y }-z \hat{ z } .
K \times ᴫ \quad=K\left|\begin{array}{ccc}\hat{ x } & \hat{ y } & \hat{ z } \\-\sin \phi & \cos \phi & 0 \\(s-R \cos \phi) & (-R \sin \phi) & (-z)\end{array}\right|=K[(-z \cos \phi) \hat{ x }+(-z \sin \phi) \hat{ y }+(R-s \cos \phi) \hat{ z }] ;
ᴫ^{2}=z^{2}+R^{2}+s^{2}-2 R s \cos \phi .
The x and y components integrate to zero (z integrand is odd, as in Prob. 5.18).
B_{z}=\frac{\mu_{0}}{4 \pi} K R \int \frac{(R-s \cos \phi)}{\left(z^{2}+R^{2}+s^{2}-2 R s \cos \phi\right)^{3 / 2}} d \phi d z=\frac{\mu_{0} K R}{4 \pi} \int_{0}^{2 \pi}(R-s \cos \phi)\left\{\int_{-\infty}^{\infty} \frac{d z}{\left(z^{2}+d^{2}\right)^{3 / 2}}\right\} d \phi
\text { where } d^{2} \equiv R^{2}+s^{2}-2 R s \cos \phi . \text { Now } \int_{-\infty}^{\infty} \frac{d z}{\left(z^{2}+d^{2}\right)^{3 / 2}}=\left.\frac{2 z}{d^{2} \sqrt{z^{2}+d^{2}}}\right|_{0} ^{\infty}=\frac{2}{d^{2}} .
=\frac{\mu_{0} K R}{2 \pi} \int_{0}^{2 \pi} \frac{(R-s \cos \phi)}{\left(R^{2}+s^{2}-2 R s \cos \phi\right)} d \phi ;(R-s \cos \phi)=\frac{1}{2 R}\left[\left(R^{2}-s^{2}\right)+\left(R^{2}+s^{2}-2 R s \cos \phi\right)\right] .
=\frac{\mu_{0} K}{4 \pi}\left[\left(R^{2}-s^{2}\right) \int_{0}^{2 \pi} \frac{d \phi}{\left(R^{2}+s^{2}-2 R s \cos \phi\right)}+\int_{0}^{2 \pi} d \phi\right] .
\int_{0}^{2 \pi} \frac{d \phi}{a+b \cos \phi}=2 \int_{0}^{\pi} \frac{d \phi}{a+b \cos \phi}=\left.\frac{4}{\sqrt{a^{2}-b^{2}}} \tan ^{-1}\left[\frac{\sqrt{a^{2}-b^{2}} \tan (\phi / 2)}{a+b}\right]\right|_{0} ^{\pi}
=\frac{4}{\sqrt{a^{2}-b^{2}}} \tan ^{-1}\left[\frac{\sqrt{a^{2}-b^{2}} \tan (\pi / 2)}{a+b}\right]=\frac{4}{\sqrt{a^{2}-b^{2}}}\left(\frac{\pi}{2}\right)=\frac{2 \pi}{\sqrt{a^{2}-b^{2}}} . \text { Here } a=R^{2}+s^{2} ,
b=-2 R s, \text { so } a^{2}-b^{2}=R^{4}+2 R^{2} s^{2}+s^{4}-4 R^{2} s^{2}=R^{4}-2 R^{2} s^{2}+s^{4}=\left(R^{2}-s^{2}\right)^{2} ; \sqrt{a^{2}-b^{2}}=\left|R^{2}-d^{2}\right| .
B_{z}=\frac{\mu_{0} K}{4 \pi}\left[\frac{\left(R^{2}-s^{2}\right)}{\left|R^{2}-s^{2}\right|} 2 \pi+2 \pi\right]=\frac{\mu_{0} K}{2}\left(\frac{R^{2}-s^{2}}{\left|R^{2}-s^{2}\right|}+1\right) .
Inside the solenoid, s<R, \text { so } B_{z}=\frac{\mu_{0} K}{2}(1+1)=\mu_{0} K . Outside the solenoid, s>R, \text { so } B_{z}=\frac{\mu_{0} K}{2}(-1+1)=0 .
Here K=n I, \text { so } B =\mu_{0} n I \hat{ z }(\text { inside), and } 0 \text { (outside) } (as we found more easily using \text { Ampére }’s law, in Ex. 5.9).