I have coded a simulation where $n$ equal charges are randomly placed on the surface of the conducting sphere. I added a damping term proportional to velocity so that the charges arrange in a stable configuration. Then the graphics of polyhedron with charges as vertices is displayed.
It works for every number of charges less than 78. It takes my computer around 20 seconds for 77 but for 78 or greater it just freezes.
Below is the code. Under each defined function there is a description of what it does
Is there a way to fix it? Thanks in advance.
NaključnaTNaKrogli[r_: 1] := {
{x, y, z} = {RandomReal[{-1, 1}], RandomReal[{-1, 1}],
RandomReal[{-1, 1}]};
If[x^2 + y^2 + z^2 < 1,
r {x, y, z}/Sqrt[x^2 + y^2 + z^2],
NaključnaTNaKrogli[r]]
}[[1]];
(*returns random point on the sphere of radius r, centered at {0,0,0}*)
l[vektor_] := Sqrt[vektor.vektor];
(returns magnitude(length) of a vector)
L[sez_] := l /@ sez;
Strešca[vektor_] := vektor/l[vektor];
STREŠCA[sez_] := sez/L[sez];
sez[CapitalDelta]r[sezr_, n_, i_] :=
ConstantArray[sezr[[i]], n - 1] - Delete[sezr, i];
(returns list of vectors from i'th charge to all other charges in
sezr. n=Length[sezr])
F[sezr_, n_, i_, c_] := {
s = sez[CapitalDelta]r[sezr, n, i];
c Total[s/L[s]^3]
}[[1]];
(returns list of force vectors of other charges on i'th charge in
sezr. c is q^2/(4Subscript[[Pi][Epsilon], 0]))
Seza[sezr_, n_, c_, m_, k_, sezV_] := {
rstre = STREŠCA[sezr];
sezF =
Reap[
Do[
Sow[
F[sezr, n, j, c]
]
, {j, n}]
][[2]][[1]];
(sezF - rstre (Total /@ (rstre sezF)) - k sezV)/m
}[[1]];
(returns list of acceloration vectors of charges. sezV is a list of
velocities of charges)
Pol[n_] := {
vmax = 1;
amax = 1;
sezr = Reap[
Do[
Sow[NaključnaTNaKrogli[]]
, n]
][[2]][[1]];
sezv = ConstantArray[{0, 0, 0}, n];
seza = ConstantArray[{0, 0, 0}, n];
t = 1/60;
dt = 1/60;
While[
(Not[
IntegerQ[
t]]) [Or] ((Max[L[sezv]] > vmax) [And] (Max[L[seza]] >
amax)),
seza = Seza[sezr, n, 100, 1, 1, sezv];
sezv += seza dt;
sezr += sezv dt;
sezr /= L[sezr];
t += dt;
];
<< TetGenLink`;
{coords, incidences} = TetGenConvexHull[sezr];
Show[
Graphics3D[{
EdgeForm[],
FaceForm[Cyan],
GraphicsComplex[coords, Polygon[incidences]]}],
Background -> Black,
Boxed -> False
]
}[[1]];
(returns graphics of polihedron with charges in end state as
vertecies)
Pol[78]

l[vektor_] := Sqrt[vektor.vektor];yourself. Just useNorm[vektor]and alsovektor/l[vektor];just useNormalize[vektor]. For the random point on the sphere, just useRandomPoint[Sphere[{0,0,0},r]]. You're using a strange patternReap[Do[Sow...in some places where you could just use aTable. You may also be interested inSpherePoints– flinty Jun 28 '20 at 00:32