Maxwell's Distribution

Init

Histogram

Although the particles in this simulation have the same initial kinetic energy, collisions quickly redistribute this energy.  Although it appears that the speed of each particle is random, the distribution of speeds is not and follows the well know Maxwellian distribution of speeds.

This page contains two Physlets that are able to share data using their common superclass, SApplet. In particular, the ensemble calculates a histogram of the particle speeds and delivers this data to the graph.


Script Example

<script language="JavaScript">

function speed(){
    npart=40;
    document.Molecular.setAutoRefresh(false); 
    document.Molecular.setDefault();
    document.Molecular.setShowControls(false);
    document.Molecular.setPeriodicH(false);
    document.Molecular.setPeriodicV(false);
    document.Molecular.createParticles(npart);
    for(i=0;i<npart;i++){
       document.Molecular.setParticlePos(i,-4+8*Math.random(),-4+8*Math.random());
       document.Molecular.setParticleVel(i,3,0);
    }
    hid=document.Molecular.getHistogramID(20,0.0,10.0);
    document.Molecular.setAutoRefresh(true);

    document.DataGraph.setAutoscaleX(false);
    document.DataGraph.setAutoscaleY(false);
    document.DataGraph.setMinMaxX(0,8.0);
    document.DataGraph.setMinMaxY(0,npart/2);
    document.DataGraph.clearSeries(1);
    document.DataGraph.setSeriesStyle(1,false,-3);
    document.DataGraph.setSeriesRGB(1,255,0,0);
    document.DataGraph.setAutoReplaceData(1,true);
    document.DataGraph.setMarkerSize(1, 1.0)

    document.DataGraph.setLabelY("N"); 
    document.DataGraph.setLabelX("|v|"); 
    document.DataGraph.setTitle("Speed"); 

    gid=document.DataGraph.getGraphID();
    document.Molecular.deleteDataConnections(); 
    cid=document.Molecular.makeDataConnection(hid,gid,1,"v","n");   
    document.Molecular.setConnectionStride(cid,4);
    document.Molecular.forward();
}
</script>