Is this process to compute the electrostatic potential energy a valid one?

I'm trying to compute the electrostatic potential energy of a uniformly charged sphere of radius a with charge Q, but I'd like to do it by brute force, I mean, by calculating directly the work done on the charge inside the sphere when I bring it from infinity to its final position.

The process to assemble the charge is as follows:

We start with a sphere of radius infinitely-long, with uniformly distributed charge Q, and then we compress the sphere very slowly (I think the term is "quasi-statically") to its final radius $a$. Note that the density is uniform at every instant of the process.

Now let's compute the work.

Let $l$ be the radius of the sphere at some point of the process. The electric field inside a uniform sphere of radius $l$ at a distance $\frac{rl}{a}$ from its centre is

$$\vec{E}=\frac{Q\frac{rl}{a}}{4\pi\epsilon_{0} l^3}\vec{u_{r}}=\frac{Qr}{4\pi\epsilon_{0} l^2a}\vec{u_{r}}$$

and the charge $dq$ of a spherical shell at that distance $\frac{rl}{a}$ is

$$dq=\rho dV= \frac{3Q}{4\pi l^3}4 \pi (\frac{rl}{a})^2\frac{l}{a}dr=\frac{3Qr^2}{a^3}dr$$

Then the work done on the charge $dq$ when we slighty compress the sphere by an amount $dl$ is

$$dW_{dq}=-\vec{F}\vec{dl}=-\vec{E}dq\vec{dl} =-\frac{3Q^2r^3}{4\pi\epsilon_{0} l^2 a^4}drdl$$

To get the total work on $dq$ we integrate all over the distance of our path, from $l=\infty$ to $l=a$ and we get

$$W_{dq}=\frac{3Q^2r^3}{4\pi\epsilon_{0} a^5}dr$$

Now if we integrate over all the charge of the sphere from $r=0$ to $r=a$ we obtain

$$W_{sphere}=\frac{3Q^2}{16\pi\epsilon_{0} a}$$

which is not the desired result,

$$W_{sphere}=\frac{3Q^2}{20\pi\epsilon_{0} a}$$

if we use other formulae to get the electrostatic potential energy.

I'm not quite sure where my mistake is, but I think the process I used might not be a valid one, since we are not dealing with point charges, or whatever reason. Any hints on where my mistake is? Thanks for your help.

• An infinite sphere will have infinite charge, plus you haven't defined $Q$, or $r$. You shouldn't start with an infinite sphere, but with just your regular sphere of radius $a$ , find the potential at radius r due to charge enclosed and use that to find the energy of an infinitesimally thin sphere with charge dq at that radius and integrate. – GeeJay Apr 12 '17 at 14:33
• An infinite sphere doesn't have to have infinite charge. The charge of the sphere, Q, remains constant throughout the whole process as I squeeze the sphere. Obviously, the density should increase, yet kept uniform. r is the position of $dq$ when the sphere has reached its final configuration, that is, with radius a. – alfdc80 Apr 12 '17 at 14:57