388 12 Random walks and the Metropolis algorithm
0
20
40
60
80
100
0 20 40 60 80 100
σ^2
Time stepst
Fig. 12.3Time development ofσ^2 for a random walker. 100000 Monte Carlo samples were used with the
function ran1 and a seed set to− 1.
-0.04
-0.02
0
0.02
0.04
0 20 40 60 80 100
〈x(t)〉
Time stepst
Fig. 12.4Time development of〈x(t)〉for a random walker. 100000 Monte Carlo samples were used with the
function ran1 and a seed set to− 1.
∂w(x,t)
∂t
≈
w(i,n+ 1 )−w(i,n)
∆t
,
whereas the gradient is approximated as
D
∂^2 w(x,t)
∂x^2
≈D
w(i+ 1 ,n)+w(i− 1 ,n)− 2 w(i,n)
(∆x)^2
,
resulting in the discretized diffusion equation