Electric Field by integral method is not the same as for Gauss's Law I'm trying to calculate the Electric Field over a thick spherical sphere with charge density $\rho = \frac{k}{r^2}$ for $a < r < b$, where $a$ is the radius of the inner surface and $b$ the radius of the outer surface.
From Gauss's Law I've got it to be $\vec{E} = \frac{k}{\epsilon_0}\frac{r-a}{r^2}$. But also tried to integrate the charge over the surface and I was hoping to get the same result but didn't. My attempt was, in spherical coordinates:
$$
\begin{equation}
\begin{aligned}
\vec{E} &= \frac{1}{4 \pi \epsilon_0}\int_a^r \int_0^\pi \int_0^{2\pi} \frac{\rho r^2 \sin \phi}{r^2} d\theta d\phi dr \vec{e_r}\\ &= \frac{1}{4 \pi \epsilon_0}\int_a^r \int_0^\pi \int_0^{2\pi} \frac{k \sin \phi}{r^2} d\theta d\phi dr \vec{e_r}\\ \\ &= -\frac{k}{\epsilon_0}(\frac{1}{r} - \frac{1}{a})\\ &= \frac{k}{\epsilon}\frac{r-a}{ra}\vec{e_r}
\end{aligned}
\end{equation}
$$
Which are not the same. But they should be! I know that my Gauss method gave me the right expression, but I can't figure out why the integral method didn't.
 A: This is mostly a supplement to Mark Viola's answer as he has a more succinct calculation. There are a few problems with your integral setup. You were not careful enough to distinguish between your integration variables and your limit variables. This is why expressions such as
$$\int_a^x f(x)\:dx$$
are frowned upon. The other issue is you treat terms like $\vec{e}_r$ as constants to pull out of the integral, when in reality they have angular dependencies. To avoid this issue altogether compute the potential and take its gradient instead. The real volume integral should be
$$\phi(r) = \frac{1}{4\pi \epsilon_0}\int_0^{2\pi}\int_0^\pi \int_a^b\frac{\rho(r')}{|r-r'|}\:r'^2\sin\theta'\:dr'\:d\theta'd\phi'$$
Notice that in this version, the volume integral is also over the entire shell instead of just a part of it. Continuing on,
$$ = \frac{k}{2\epsilon_0}\int_a^b\int_0^\pi \frac{\sin\theta'\:dr'\:d\theta'}{\sqrt{r^2+r'^2-2rr'\cos\theta'}} = \frac{k}{2\epsilon_0}\int_a^b \frac{|r-r'|-|r+r'|}{rr'}dr'$$
$$ = -\frac{k}{\epsilon_0}\int_r^b \frac{dr'}{r'} - \frac{k}{\epsilon_0}\int_a^r\frac{dr'}{r} = -\frac{k}{\epsilon_0}\left(\log\left(\frac{r}{b}\right)-\frac{r-a}{r}\right)$$
The electric field is then given by
$$\vec{E} = -\nabla \phi = \frac{k\hat{e}_r}{\epsilon_0}\left(\frac{1}{r}-\frac{a}{r^2}\right) = \frac{k\hat{e}_r}{\epsilon_0}\left(\frac{r-a}{r^2}\right)$$
which is exactly the answer you arrived at from Gauss' law.
A: The issue is an inconsistency in the way you use the symbol $r$.
Coulomb's law says that the electric field at a point $\mathbf r$ arising from a charge at a point $\mathbf r'$ is inversely proportional to $|\mathbf r - \mathbf r'|^2$, and is directed along the vector $\mathbf r - \mathbf r'$. The $r^2$ that appears in your definition of the charge density refers to the distance from the origin of your coordinate system to where the charge is located.
The integral you should be solving therefore looks as follows:
$$
\mathbf{E}(\mathbf r) = \int_a^R\int_0^{\pi}\int_0^{2\pi} \frac{\rho(r') r'^2\sin \phi}{|\mathbf{r} - \mathbf{r}'|^2} \widehat{\mathbf{r} - \mathbf{r}'}\mathrm{d}\theta\,\mathrm{d}\phi\, \mathrm{d}r',
$$
and that does indeed give the expected result, but the calculation is a bit of a slog.
A: For $a<r<b$ we have from Coulomb's law that
$$\begin{align}
\vec E(\vec r)&=\frac1{4\pi \varepsilon_0}\int_V \rho(\vec r')\frac{\vec r-\vec r'}{|\vec r-\vec r'|^3}\,dV'\\\\
&=-\frac1{4\pi \varepsilon_0}\nabla \int_V \rho(\vec r')\frac{1}{|\vec r-\vec r'|}\,dV'\\\\
&=-\frac1{4\pi \varepsilon_0}\nabla \int_a^b \int_0^{2\pi}\int_0^\pi \frac{k}{r'^2}\frac{1}{(r^2+r'^2-2rr'\cos(\gamma))^{1/2}}\,r'^2\sin(\gamma)\,d\gamma\,d\phi\,dr'\\\\
&=-\frac{k}{2 \varepsilon_0}\nabla \int_a^b \int_0^\pi \frac{\sin(\gamma)}{(r^2+r'^2-2rr'\cos(\gamma))^{1/2}}\,d\gamma\,dr'\\\\
&=-\frac{k}{2 \varepsilon_0}\nabla\int_a^b \frac{(r+r')-|r-r'|}{rr'}\,dr'\\\\
&=\hat r\frac{k(r-a)}{\varepsilon_0 r^2}
\end{align}$$
as expected!
Note we exploited the spherical symmetry of the problem by rotating the primed coordinates to align with the polar axis in the unprimed coordinates.
