An introduction to statistical physics with simple examples

Hugo Touchette
School of Mathematical Sciences
Queen Mary University of London
London, United Kingdom
ht@maths.qmul.ac.uk

Started: 9 April 2012
Last updated: 13 April 2012

Presentation at http://www.maths.qmul.ac.uk/~ht/talks/

Random walks

1D random walk

BiasedStep[a_]:=If[RandomReal[]<a,-1,1]

With[{Nrw=1,Nsteps=100,a=0.5},
rwlist={};
Do[
steplist=Table[BiasedStep[a],{i,Nsteps}];
rw=FoldList[Plus,0,steplist];
AppendTo[rwlist,rw];
,{j,Nrw}];
ListPlot[Evaluate@rwlist,Joined->True]
]

Binomial distribution

With[{a=0.5,Nsteps=40},
DiscretePlot[PDF[BinomialDistribution[Nsteps,a],(Nsteps-s)/2],{s,-Nsteps,Nsteps,1},PlotRange->All,ExtentSize->1,Frame->True,Joined->False]
]

2D random walk

With[{Nsteps=1000},
moves={{0,-1},{-1,0},{0,1},{1,0}};
randommoves=Table[RandomChoice[moves],{i,Nsteps}];
traj=FoldList[Plus,{0,0},randommoves];
maxv=Max[Abs[traj]];
box={EdgeForm[Thin],Transparent,Rectangle[{-maxv,-maxv},{maxv,maxv}]};
Graphics[{box,Line[traj]}]
]

3D random walk

With[{Nsteps=1000},
moves={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};
randommoves=Table[RandomChoice[moves],{i,Nsteps}];
traj=FoldList[Plus,{0,0,0},randommoves];
maxv=Max[Abs[traj]];
box={EdgeForm[Thin],Transparent,Rectangle[{-maxv,-maxv},{maxv,maxv}]};
Graphics3D[Line[traj]]
]

Brownian motion

1D

BrownianMotion1[σ_,T_,dt_]:=Module[{TimeList,dB,BMt},
TimeList=Range[0,T,dt];
dB=(Sqrt[dt])RandomReal[NormalDistribution[0,σ],T/dt];
BMt=Transpose[{TimeList,FoldList[Plus,0,dB]}]
]

ListPlot[Table[BrownianMotion1[1,1,0.01],{2}],Joined->True,PlotRange->All,Frame->True]

2D trace

BMDynamics[{x_,y_},σ_]:={x,y}+RandomVariate[NormalDistribution[0,σ],{2}]

With[{dt=0.01,σ=1,N=1000,v=5},
traj=NestList[BMDynamics[#,σ (Sqrt[dt])]&,{0,0},N];
maxv=Max[Abs[traj]];
box={EdgeForm[Thin],Transparent,Rectangle[{-maxv,-maxv},{maxv,maxv}]};
Graphics[{box,Line[traj]}]
]

2D animation

With[{dt=0.01,σ=1,v=5},
box={EdgeForm[Thin],Transparent,Rectangle[{-v,-v},{v,v}]};
pos={0,0};
Graphics[{box,Disk[Dynamic[pos=BMDynamics[pos,σ (Sqrt[dt])]],0.2]}]
]

2D animation with trace

With[{dt=0.01,σ=1,v=5},
box={EdgeForm[Thin],Transparent,Rectangle[{-v,-v},{v,v}]};
{x,y}={0,0};
traj={{x,y}};
Graphics[{box,Line[Dynamic[AppendTo[traj,BMDynamics[Last[traj],σ (Sqrt[dt])]]]]}]
]

Many particles

With[{dt=0.01,σ=0.1,v=100,Npart=2},
box={EdgeForm[Thin],Transparent,Rectangle[{-v,-v},{v,v}]};
pos=Table[{0,0},{i,Npart}];
Graphics[{box,Point[Dynamic[pos=(BMDynamics[#,1]&/@pos)]]}]
]

Galton board (and the binomial distribution)

With[{nmax=20,p=0.5},
σ=StandardDeviation[BinomialDistribution[nmax,p]];
p1=DiscretePlot[PDF[BinomialDistribution[nmax,p],i],{i,0,nmax},Frame->True,PlotRange->All,ExtentSize->1];
p2=Plot[PDF[NormalDistribution[nmax/2,σ],x],{x,0,nmax},PlotRange->All,PlotStyle->Red];
Show[{p1,p2}]
]

Maxwell’s distribution

Boltzmann’s constant:

kB=1.380648 ×(10^(-23));

Mass of diatomic nitrogen (Subscript[N, 2]):

mN2=2 14.0067 × 1.660538×(10^(-27));

pmaxwell[v_,T_,m_]:=(Sqrt[(2/π)((((m/(kB T))))^3)])(v^2) Exp[-((m (v^2))/(2 kB T))]

Plot[pmaxwell[v,300,mN2],{v,0,2000}]

(Sqrt[((2 kB 300)/mN2)])

Plot[Evaluate@Table[pmaxwell[v,T,mN2],{T,100,300,100}],{v,0,2000}]