I am trying to plot the electric potentials of bouncing balls using the following code:
g = 0.1;
Tmax = 100;
n = 6;
pos = RandomReal[{-1, 1}, {n, 2}];
charge = RandomReal[{1, 10}, 10];
sol = NDSolve[
Flatten@Table[{
With[{i = i},
{(x[i])''[t] == 0,
(x[i])'[0] == 0,
(y[i]'')[t] == -g,
(y[i])'[0] == 0,
x[i][0] == pos[[i, 1]],
y[i][0] == pos[[i, 2]],
WhenEvent[
y[i][t] < -1, {y[i]'[t] -> -0.95 y[i]'[t],
y[i][t] -> y[i][t] + 0.05}]
}
]
}, {i, 1, n}], Flatten@Table[{x[i], y[i]}, {i, 1, n}], {t, 0, Tmax}, PrecisionGoal -> 2];
Manipulate[Graphics[
Table[
With[{p = Evaluate[
{x[i][t], y[i][t]} /. First[sol]]},
Disk[p, 0.05]], {i, 1, n}], PlotRange -> 1.05], {t, 0, Tmax}]
PotentialAnimated[x_, y_, t_] :=
Sum[charge[[i]]/
If[Norm[({x, y} - {x[i][t], y[i][t]} /. sol)] > 0.001,
Norm[({x, y} - {x[i][t], y[i][t]} /. sol)], 0.001],
{i, 1, n}]
Manipulate[
DensityPlot[PotentialAnimated[x, y, t], {x, -1, 1}, {y, -1, 1}], {t, 0, 10}]
This^ last command should plot the potentials in my box caused by the charged balls jumping up and down, but I get an almost fractal looking artifact from my lower left to my upper right corner. Any ideas why this is happening ?
// part 2
not directly related but I feel like it would be a waste to start a new question just for this.
Im now trying to combine the two plots like this:
Manipulate[ Show[{DensityPlot[ PotentialAnimated[x, y, t], {x, -10, 10}, {y, -10, 10}, ColorFunction -> "SunsetColors"], Graphics[ Table[ With[{p = {x[i][t], y[i][t]} /. First[sol]}, {ColorData["TemperatureMap", (charge[[i]] + 10)/20], Disk[p, 0.5]} ] , {i, 1, n}] , PlotRange -> 10.5, Background -> Black]}], {t, 0, Tmax}]
for charges ranging from -10 to 10 , but it seems like the colors get "clipped" on the density plot
how can I fix it so colours near the balls dont just go white.
thx for the help so far
catadoxas