How long time does it take before three planets achieve the same relative position?
The answer is never, except for the case when their orbital periods can be expressed with low integers, like the 4:2:1 resonance of Io, Europa and Ganymede
However, what you are asking about is when they are going to be in almost the same position again, a quazi-period.
To find those periods, we are pretty much only left by brute forcing as our method. A nice little detail about the case with three planets is that the inner planet is always aligned with one of the other ones at the closest three-planet alignments. That allows us to calculate accurate solutions. In the cases of four or even five planets I simply give up.
To check all the possibilities, we can use a program. Here is an example of a function in JavaScript returning a list of quazi-periods and alignment error:
sameLine = function (period1,period2,period3,limit){
results = [];
newMargin = 1;
synodic1 = 1/(1/period1 - 1/period2);
anomaly1 = (synodic1/period1) % 1;
synodic2 = 1/(1/period1 - 1/period3);
anomaly2 = (synodic2/period1) % 1;
alert(synodic1+","+synodic2);
for (i = synodic2; i < limit; i+=synodic2){
numb1 = i/synodic1 - (i/synodic1) % 1;
numb2 = i/synodic2 - (i/synodic2) % 1;
err1 = Math.abs((numb1 * anomaly1 - numb1 * synodic1/period3) % 1);
err2 = Math.abs((numb2 * anomaly2 - numb2 * synodic2/period2) % 1);
if (err1 > 1 - err1){
err1 = 1 - err1;
};
if (err2 > 1 - err2){
err2 = 1 - err2;
};
if ((err1 < newMargin) && (numb1 > 0)){
results.push([numb1 * synodic1,err1]);
newMargin = err1;
};
if ((err2 < newMargin) && (numb2 > 0)){
results.push([numb2 * synodic2,err2]);
newMargin = err2;
};
};
return results;
};
For Jupiter, Saturn and Uranus, I get the following output:
Time,,,error
13.81170069444156,,,0.30449020900657225
39.71676854387252,,,0.12441143762575813
41.43510208332468,,,0.08652937298028318
139.00868990355383,,,0.06455996830984656
138.1170069444156,,,0.04490209006572288
179.55210902774027,,,0.041627282914560304
317.6691159721559,,,0.0032748071511630172
3991.581500693611,,,0.002329597100612091
4309.250616665767,,,0.0009452100505313865
The first of this periods is of no use, as the error in alignment is almost a third of an orbit. Note that the one you found (that is really impressive you did,actually) gives an error in the alignment of less than a percent. We have to look at periods more than a thousand years long to find any better alignment.
Be sure to feed this function with accurate orbital periods.
The gravitational potential energy of a polytropic sphere of gas (i..e governed by a polytropic equation of state), with a polytropic index $n$ is given by
$$ \Omega = -\frac{3}{5-n}\ \frac{GM^2}{R}$$
See for example here.
A constant density sphere would have to have to be incompressible. Since a polytrope has a pressure $p \propto \rho^{1 +1/n}$, this corresponds to $n=0$ and gives you your result for a uniform sphere.
Higher values of $n$ have more centrally condensed profiles and larger binding energies.
The appropriate value of the polytropic index for brown dwarfs and gas giants, where energy transport is convective or where the gas is (non-relativistically) degenerate is $n=3/2$.
In which case, your leading coefficient increases from 3/5 to 6/7. i.e. No big deal for an approximate calculation.
Best Answer
Your experiment with real data is fantastic! I applaud your curiosity, and investigation into the planets. Unfortunately, I don't think there's anything to your results (sorry!).
Astrophysics
The conventional wisdom used to be that planetary density would decrease with increasing distance away from a parent star, because that's what the disks around young stars look like [1] before they form planets. This idea completely fails in light of exoplanetary data which now includes thousands of planets in many hundreds of star systems. The end result is that planet formation is extremely complicated, and different types of planets tend to form in different places. In addition to that, there are numerous reasons to believe that planets move around a good amount after they've formed. So, observationally, there is no consistent relation between density and distance.
Statistics
If you try to plot enough relations, things will fit (e.g. Kepler's Shapes, and the Titus-Bode Law). The robustness of trends and correlations drop rapidly when, 1) data is arbitrary excluded (e.g. Mercury and Venus), 2) arbitrary split up your data, and 3) use arbitrary measures of goodness of fit (e.g. how close points look to a line on a certain plot). In fact, for robust statistical measurements, one needs to consider how many models were attempted to be fit, before considering how robust results seem.
[1] Even this is only approximately true... there were some more complicated reasons based on lifetimes of different substances in the disks, but that's not too important here.