# Sphere of uniform charge density with a cavity problem

Suppose we have a sphere of radius $R$ with a uniform charge density $\rho$ that has a cavity of radius $R/2$, the surface of which touches the outer surface of the sphere. The question was to calculate the field inside the cavity.

Naively, I used Gauss' law to determine that $\mathbf{E}=0$ inside the cavity. However, the solution I have stated that the field is actually the superposition of the field of the sphere without the cavity, and the field of the cavity, wherein the charge density is the negative of that of the original sphere. So, \begin{align} \mathbf{E}_{\text{inside sphere}}&=\frac{\rho}{3}(x,y,z)\\ \mathbf{E}_{\text{inside cavity}}&=-\frac{\rho}{3}(x+R/2,y,z)\\ \\ \Longrightarrow \ \mathbf{E}_{\text{net inside cavity}}&=\mathbf{E}_{\text{inside sphere}}+\mathbf{E}_{\text{inside cavity}}\\ &=-\frac{\rho R}{6}(1,0,0). \end{align} I am confused by the rationale of this approach, and also why Gauss' law gives the incorrect answer.

The problem I see in your solution is with adding the $R/2$ term for the field inside the cavity (the negatively charged sphere that makes the "cavity"). The field inside of a uniformly charge sphere with charge density, $\rho$, can be found using Gauss' law to be:
$\vec{E}(r) = \frac{\rho r}{3\epsilon_0} \hat{r}$
Your notation is slightly different, but I think it is essentially the same thing. But what you notice, is that inside the sphere, the value of the electric field only cares about the charge density, since Gauss' law in this symmetric situation is only concerned with the charge inside your Gaussian surface. The same is true for the oppositely charged sphere, where the only difference should be a '-' sign up to the point $r=R/2$. Therefore, the electric fields are equal and opposite inside the cavity, so $\vec{E} = 0$ inside the cavity, and both superposition and Gauss' law produce the same result as they should.
$\rho$ is zero for any coordinate inside the cavity.