I am trying to write a Mathematica program that realizes a graphical approximation of the basins of attraction in a Magnetic pendulum subject to friction and gravity, in which the three magnets are disposed on the vertices of an equilateral triangle. This system is chaotic and has very interesting properties. The basins of attraction look something like this:
A code I wrote can produce a $400 \times 400$ image such as this (Caution: no fancy ColorFunctions involved) in about two hours. The computation seems to be extremely slow.
Is there any way of having a better rendering, say, full HD 1920x1080 resolution, for the basins of attraction of a magnetic pendulum as the one mentioned that can be run in a farely quick time on a common machine?
Code
Here is the code I used to produce the above image. I set the position of the magnets and define the Lagrange equations
X1 = 1; X2 = -(1/2); X3 = -(1/2); Y1 = 0; Y2 = Sqrt[3]/2; Y3 = -(Sqrt[3]/2);
X[1] = X1; X[2] = X2; X[3] = X3; Y[1] = Y1; Y[2] = Y2; Y[3] = Y3;
Eqs[k_,c_,h_]:={
x''[t]+k x'[t]+c x[t]-Sum[(X[i]-x[t])/(h^2+(X[i]-x[t])^2+(Y[i]-y[t])^2)^(3/2),{i,3}]==0,
y''[t]+k y'[t]+c y[t]-Sum[(Y[i]-y[t])/(h^2+(X[i]-x[t])^2+(Y[i]-y[t])^2)^(3/2),{i,3}]==0
}
I define a function that numerically integrates the equations up until $t=100$.
Sol[k_, c_, h_, xo_, yo_] :=
NDSolve[
Flatten[{Evaluate[Eqs[k, c, h]],
x'[0] == 0, y'[0]== 0, x[0] == xo, y[0] == yo}],
{x, y}, {t, 99.5, 100.5}, Method -> "Adams"
];
I define a function tt that gives a value between $\frac13, \frac 23, 1$ based on magnet proximity at time $100$ for fixed $k,c,h$ (in this case $.15$,$.2$,$.2$) and a function k that evaluates tt on a grid.
tt = Compile[{{x1, _Real}, {y1, _Real}}, Module[{},
Final = ({x[100], y[100]} /. (Sol[0.15, .2, .2, x1, y1])[[1]]);
Distances = Map[(Final - #).(Final - #) &, {{1, 0}, {-(1/2), Sqrt[3]/2}, {-(1/2), -(Sqrt[3]/2)}}];
Magnet = Min[Distances];
Position[Distances, Magnet][[1, 1]]/3]];
k[n_, xm_, ym_, xM_, yM_] := ParallelTable[tt[xi, yi], {yi, ym, yM, Abs[yM - ym]/n}, {xi, xm, xM, Abs[xM - xm]/n}];
Finally, I rasterize the table produced by k.
G = Graphics[Raster[k[400, -2, -2, 2, 2], ColorFunction -> Hue]]
and, after a while, I obtain the previous image. I attempted using a dynamic energy control (i.e. using EvaluationMonitor to monitor the energy level of ther trajectory: if it falls in a potential hole NDSolve throws the position) but this did not increase the speed as much as I was hoping; it actually seems to slow the computation down.






Y3 = -(Sqrt3]/2);) in the first code block. When I runSol[0.15, .2, .2, 1, 1]I get an error message saying that the system is undetermined, because of lack of spaces betweencandxandy. – C. E. Jul 18 '16 at 11:57NDSolve[]for this specific case. – J. M.'s missing motivation Jul 18 '16 at 18:01