Solution (source code)

= Solution

The collapse is perpendicular to the initial field, so <magnetic flux freezing> preserves the <mass-to-flux ratio> of each material flux tube:
$$
\frac{B_z}{\rho}=\frac{B_0}{\rho_0},
\qquad
B_z=\frac{B_0}{\rho_0}\rho.
$$
With no toroidal field, radial <magnetostatic equilibrium> is
$$
\frac d{dR}\left(P+\frac{B_z^2}{8\pi}\right)
=-\rho\frac{d\Phi}{dR}.
$$
Define the effective polytropic constant
$$
K_{
m eff}=K+\frac{B_0^2}{8\pi\rho_0^2}.
$$
Then gas and <magnetic pressure> combine as $P+B_z^2/(8\pi)=K_{\rm eff}\rho^2$. Dividing equilibrium by $\rho$, differentiating, and using the cylindrical <Poisson equation>
$$
\frac1R\frac d{dR}\left(R\frac{d\Phi}{dR}\right)=4\pi G\rho
$$
gives
$$
\boxed{
\frac1R\frac d{dR}\left(R\frac{d\rho}{dR}\right)
+\frac{2\pi G}{K_{\rm eff}}\rho=0}.
$$
Put $a^2=K_{\rm eff}/(2\pi G)$. This is the order-zero <Bessel differential equation>, and regularity on the axis together with $\rho(0)=\rho_1$ yields
$$
\boxed{\rho(R)=\rho_1J_0(R/a)}.
$$