Random Walks

This notebook simulates a random walk for a particle of given mass in a medium of given temperature.  Each frame represents a different walk, starting at the origin.

WalkCoords:=FoldList[Plus,{0,0,0},
		Table[{xa=Random[Real,{-ran[i],ran[i]}],
			ya=Random[Real,{-ran[i],ran[i]}],
			za=Random[Real,{-ran[i],ran[i]}]},{i,steps}]];
Walk:=(vel=N[Sqrt[3*1.38*(10^-23)*temp/m]];
	dt = 1.30834 * 10^(-11);
	siz=N[10*Sqrt[2vel*mfp*steps*dt]/zoom];
	tend = steps*dt;
	ran[i_]:=N[Sqrt[2vel*mfp*dt*i/3]];
totald = 0;
Do[(Show[Graphics3D[Line[WalkCoords],
	AspectRatio->Automatic, Boxed->False,	
	PlotRange->{{-2siz,2siz},{-2siz,2siz},{-2siz,2siz}},
	Axes->True, AxesEdge->{{-1,-1},{-1,-1},{-1,-1}},
	Prolog->{Text[StringForm[
		"t= ``", steps*dt],Scaled[{0,.95}],{-1,0}],
		 Text[StringForm[
		 "x= ``", xa], Scaled[{0,.9}],{-1,0}],
		 Text[StringForm[
		 "y= ``", ya], Scaled[{0,.85}],{-1,0}],
		 Text[StringForm[
		 "z= ``", za], Scaled[{0,.8}],{-1,0}]},
		 Lighting->False]];
	Print["Distance = ",dist=Sqrt[xa^2+ya^2+za^2]];
	totald = totald + dist;),
		 {k,frames}];
Print["Average distance traveled = ",totald/frames];);

The following cell contains values which may be changed by the user:

         m is the mass in kg;
         temp is the temperature in K;
         steps is the number of steps in the walk;
         mfp is the mean free path for this medium in m;
         zoom is the zoom factor for the graph (larger ~ closer);
         frames = number of trials.

m=.114/(6.022*10^23);

temp=298;

steps=10000;

mfp=3.34*10^-9;

zoom = 1;

frames = 10;

Walk;