# How can the divergence of a cylinder with uniform magnetic field be non-zero?

When I'm calculating the divergence of a cylinder with uniform magnetic field ($$B=K=\text{constant}$$) according to the formula of divergence in cylindrical coordinates I'm getting the same constant value as the divergence.

$$\nabla\cdot B=K.$$

But from the physical explanation of divergence it should be 0 in a uniform field. What's the loophole here?

• Just because you are stating that a cylinder has a B-field" that is homogeneous and therefore its divergence is not zero does not mean that there is a loophole, instead it means that such magnetic flux density field does not exist! You can imagine (even approximately make) a cylindrically homogeneous polarization field M but its associated B -field is not constant and will have 0 divergence. Commented Aug 13 at 14:12
• I have the same idea of such field not existing,but when searching it on Google made me confused.Thanks for clarifying.
– Sch
Commented Aug 13 at 14:36
• how? is $\vec B = B\hat z$ for $\rho \le R$?
– JEB
Commented Aug 13 at 15:16

You wrote $$B=K$$ but this is not a correct way to describe the magnetic field, the magnetic field is a vector. In cylindrical coordinates, you could have $$\vec{B}=K\hat{r}$$, $$\vec{B}=K\hat{\varphi}$$ or $$\vec{B}=K\hat{z}$$. Now, the divergence operator in cylindrical coordinates would imply, for each case
$$\nabla \cdot \vec{B} = \frac{1}{r}\frac{\partial(rB_r)}{\partial r}=\frac{K}{r}, \ \nabla \cdot \vec{B}=\frac{1}{r}\frac{\partial B_{\varphi}}{\partial \varphi}=0, \ \nabla\cdot \vec{B}=\frac{\partial B_z}{\partial z}=0.$$