I have created a simple animation to explain to students how temperature affects the occupation of energy levels by using Animate
to try to continually apply a Metropolis update to a system of particles in a three-level energy system. The code looks like this:
L = 5;
s = Table[{i, 0}, {i, 1, L}];
e = {0, 1, 4}; (*allowed energy levels*)
excite[n_, T_] := (
x = RandomInteger[{1, 3}];
de = e[[x]] - s[[n, 2]];
If[de < 0,
s[[n, 2]] = e[[x]],
p = RandomReal[];
If[p < Exp[-de/T],
s[[n, 2]] = e[[x]]
]
]
)
plt = Plot[e, {i, 0, L + 1}, AspectRatio -> 1.3, ImageSize -> Small];
Animate[
Manipulate[
excite[t, T];
Show[plt, ListPlot[s, PlotStyle -> PointSize[0.05], Filling -> Axis]]
, {T, 0.1, 11}]
, {t, 1, L, 1}]
where the temperature can be controlled with Manipulate
. However, this does not act the way I would expect whatsoever. Sometimes it works rather nicely, but it sometimes will just freeze and stop updating until I try to change the temperature, and often continues to update even after I have paused the animation. Also, the rate at which it updates does not seem to be influenced at all by the step size or refresh rate of the animation. I have also tried putting the Manipulate
outside the Animate
and it has similar behavior. Is there a better way to do this?
To be clear, I want the animation to run the excite
routine for each particle at a reasonable rate. Even as I have it now, at each time step of the animation one particle should be excite
'd once per update, but when I run it sometimes a single particle will jump up and down multiple times at a single time step, I have no idea what Mathematica is doing (also I would prefer if it applied excite
to each one at once before updating the plot). When T
is low, all the particles should stay at the bottom, but when T
is high (above the maximum e
), all the levels should on average have the same number of particles, but even when I crank T
up they still seem to stay in the bottom level.
Here's an example of what it looks like:
t
anywhere in your code. Your animation is set to index{t,1,10,1}
$\endgroup$t
anywhere in the code, I simply need to animation to run continuously with discrete steps, but I don't know how to do that. I have changed the code so that which "particle" gets "excited" is linked tot
but it doesn't really make it much better. $\endgroup$T
to be fixed to demonstrate the behavior of the system at different temperatures. $\endgroup$AnimationRunning -> False
so that theT
slider doesn't move until you drag it. $\endgroup$