I am currently interested in a system, where I have a big box of charges for which the density goes to zero at the boundary. What I wanted to do is try to derive what charge density will minimize the total electrostatic energy in the box. Now a cubic box gave me some complicated so I switched the problem to be that of a sphere of radius R, for which I want to find the charge density that minimizes the total electrostatic energy. Mathematically I am therefore trying to solve the problem of finding a ρ(r) that minimizes: E = 1/4πε0 4π∫0Rρ(r) V(ρ(r)) dr with the boundary conditions: 4π∫0Rρ(r)dr = ρ0 ρ(R)=0. Now V(r) I can calculate using the symmetry of the sphere, but it will depend on ρ(r), which explains the notation above. Is it possible to use variational calculus or other means to find ρ(r) such that E is minimized? And is it possible for other geometries?