Entropy

Lauch Applet >>

This program is based on the activity given as an introduction to the idea of entropy in the Nuffield Advanced Chemistry course. It models random energy exchanges between molecules in a system. Each move, a random molecule gives one quantum of its energy to another random molecule:

11may, after one turn, become:10
1121

The initial distribution where all molecules can be seen to have the same number of quanta of energy gradually becomes closer to the Maxwell-Boltzmann distribution.

Purpose

This program carries out the specified number of random energy exchanges (see above) between 'molecules' in a grid (the system) at once, then updates the display as well as showing how many molecules have 0,1,2 etc. quanta. The number of quanta the molecules start with may be specified within the program.


The Program

This program is written in Java 2 (using the Eclipse Platform IDE). There are two versions; a Java application and an applet which can be run through the web page.

The number of quanta belonging to each 'molecule' in the grid is stored in a 2 dimensional int (32-bit integer) array (each element corresponds to one 'molecule'. Two random numbers (casted into integers) are generated using the Java Math.random() library function (the random floats generated are multiplied by the size of each dimension of the array to give numbers upto and including each element in the array). These numbers are then used as the co-ordininates of the molecule. The value at this location in the array is decremented to reflect it giving up one quantum of energy. Then, two more random numbers are generated and the element at this index is incremented to reflect the 'molecule' acquiring the quantum. This process is repeated the specified number of times.

Once all the moves have been carried out, the array is iterated through and its value is used as the text property of each element of a corresponding JTextFrame array to display the results on the screen.

The program then counts the number of 'molecules' with 0,1,2...29 quanta and displays these in JTextFrames to the side of the grid.


Screenshots

Screenshots are available via links below. They will open in external windows. The screenshots are in PNG format (which any sensible browser should be able to open). Please note that all screenshots are ©Copyright 2006 D Wilkins unless otherwise stated.

The screenshots show the Java Application version of the program.


Download

Go to the Download Page


Source Code

The source code for this program is available under the GNU General Public Licence (GPL). You are free to use, resdistribute and modify the program and its source code. References to the original author (i.e. me) are required on any distributed altered versions of this work and please make it clear that you have altered the program when redistributing so it is clear it is not entirely my work.

Download Source Code (ZIP, 6KB)

The archive contains the source code in plain text .java files for both the application and applet versions as well as a simple HTML file to view the applet. Compiled .class files are not included.


© Design and content copyright 2005-2007 D Wilkins.