If I know the positions and the speeds of each particle in a box over the time, how can I compute the entropy ?

(I`m making a simulation where I want to show that the disperion of the particles over the time increases the entropy.)

preview :

enter image description here

nb: it`s not a shower, particles are free, they are not falling...



code :

the code will be released when ready with some videos of real experimentations made. We have differents situations to program, not only the present one.


on the suggestion of qftishard I computed the entropy of the simulation presents in the video,

$$S = - k_\mathrm{B} \sum p_i \ln p_i $$

(Gibbs Entropy Formula ?)

enter image description here

nb1: I didn't use gnuplot for years, so I don't remember how to add nice title, etc. I took this screenshot quickly...

nb2: I scaled the entropy from 0 to 1 on purpose. But of course I don`t have zero entropy at the beginning of the simulation.

  • we can see that the entropy is lower when the particles are not dispersed.
  • we see the maximum of entropy (with some variations) when particles are dipsersed.
  • we see that the system never get back, even close, to his initial state.
  • we see that the entropy is rising over time to reach a maximum, so we conclude our system respect the second law of thermodynamic.
  • so, I consider this simulation succeeded! thx guys.
  • $\begingroup$ What size of box, what type of particles? $\endgroup$ – Gert Nov 23 '15 at 16:45
  • 2
    $\begingroup$ You can bin-count particles and use the log definition of entropy (en.wikipedia.org/wiki/Entropy_(information_theory)#Definition) $\endgroup$ – AccidentalFourierTransform Nov 23 '15 at 17:03
  • $\begingroup$ @Gert so far I use $width=10$ $height=20$ $\endgroup$ – The Unholy Metal Machine Nov 23 '15 at 17:29
  • 2
    $\begingroup$ @bob-theunholymetalmachine set up a 2D grid, and index each site with two integers $i,j$. Let $P_{ij}$ be the number of particles in the site $ij$, divided by the total amount of particles. The the entropy is $S~\sum_{ij} P_{ij} \log P_{ij}$. You should be able to fill in the details... $\endgroup$ – AccidentalFourierTransform Nov 23 '15 at 18:11
  • 3
    $\begingroup$ @bob-theunholymetalmachine Of course there are units in a computer simulation... if you have not set them yet for your system, go and do it!! e.g. $1 k_B T$ can be taken as unit of energy, the radius $\sigma$ of your particles as units of length (which allows you to compare its size with that of the confining box, e.g. $10\sigma,$) if the dynamics are brownian then the usual choice of units of time is the diffusion time $w$ of particles and so on! Simulation results without well defined units are utterly useless, be it for theoreticians or experimentalists. $\endgroup$ – Phonon Nov 23 '15 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.