Demonstration of Maxwell-Boltzmann speed distribution for particles in a box
-
Open
index.htmlwith a modern web browser.- WARNING: Internet Explorer is not supported, and using it may lead to unexpected behaviors.
- Note: Chrome cannot run this program properly when the program is executed as a local file. More information can be found on Issues with Chrome section of this file.
-
Open debug console. Typically it is bound to
F12on keyboard. -
Execute
simulate()
or
simulate({ tMax: 10000, dt: 50, n: 100, ... })
More options can be found on Options section of this file.
-
The simulator terminates after
tMax(default: 10,000) milliseconds. If you want to stop the simulation earlier, you can use the return value ofsimulate()function, like the code below.let instance instance = simulate() // Stopping the simulation instance.terminate()
| Name | Default | Description |
|---|---|---|
width |
320 |
Box width (px) |
height |
240 |
Box height (px) |
r |
2 |
Particle radius (px) |
tMax |
10000 |
Max simulation time (ms) |
dt |
50 |
Time interval between screen refreshes (ms) |
timestamp |
10 |
Number of screen refreshes between timestamps |
n |
100 |
Number of particles |
vMean |
0.08 |
Target mean speed of particles (px/ms) * |
dist |
'uniform' |
Speed distribution of particles (uniform / delta) |
bins |
Math.ceil(Math.log2(n)) + 1 |
Number of screen refreshes between timestamps |
xMax |
3 * vMean |
Max value of x in histogram plot |
yMax |
1.5 * pdf(vMean) ** |
Max value of y in histogram plot |
* vMean may not be equal to actual mean speed of the particles.
** pdf() is the Maxwell-Boltzmann distribution function.
simulate() function returns the web worker object responsible for
calculating positions and velocities of the particles.
- Note: If you are running the code in a web server, this section does not apply to you. The program will work as expected without any modifications.
Chrome does not allow web worker script from local files to be executed. A
workaround is present, and implemented in files in the chrome branch.
How to Download Files in chrome Branch:
- Visit the git repository.
- Above the list of files, find the button named "Branch: master"
- Among the dropdown list of branches, find "chrome".
- On the right side of the button showing branches, click "Clone or download".
- Click "Download ZIP".