0% found this document useful (0 votes)
2 views

Lec20 Random Walk

The document discusses various models of random walks, including one-dimensional and two-dimensional random walks, as well as self-avoiding walks. It presents simulation algorithms in programming languages to illustrate these concepts, highlighting their applications in diffusion and polymer modeling. Key formulas and principles related to diffusion and the behavior of random walks are also included.

Uploaded by

nadanasri007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lec20 Random Walk

The document discusses various models of random walks, including one-dimensional and two-dimensional random walks, as well as self-avoiding walks. It presents simulation algorithms in programming languages to illustrate these concepts, highlighting their applications in diffusion and polymer modeling. Key formulas and principles related to diffusion and the behavior of random walks are also included.

Uploaded by

nadanasri007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Model - 1

Random Walk
Random Walk Models

• Diffusion: Motion of a molecule in a solution,


Brownian movement etc.

• Simulation of long chain molecule: Polymers

• Simplest case: One dimensional random walk


One Dimensional Walk

• Two walkers in one dimension


Random Walk: 2D
• Two dimensional random walk
% random walk
x=[];
y=[];
x(1)=0;
y(1)=0;
for i=1:10000

J=rand;
if J<0.25
x(i+1)=x(i)+1; y(i+1)=y(i);
elseif (J>0.25)&(J<0.5)
x(i+1)=x(i)-1; y(i+1)=y(i);
elseif (J>0.5)&(J<0.75)
x(i+1)=x(i); y(i+1)=y(i)+1;
else
x(i+1)=x(i); y(i+1)=y(i)-1;
end

end
plot(x,y)
Random Walk and Diffusion

• Diffusion:
• Average of square of distance ~
step number ~ time

< x2 >= Dt
• Law of Diffusion
• D: Diffusion constant
• Mixing of a drop of cream with
coffee, when the size of cup is
changed.
Self Avoiding Walk
• Walker will not visit the site once visited.
• <x2> increases much more rapidly than simple walk.
• <x2> ~ ta , a = 1.4 (SAW) [a=1 for simple walk]
• Can simulate a polymer: No. possible configuration
governs partition function
Simple Random Walk
PROGRAM RANDOM_WALKS
IMPLICIT NONE
INTEGER, PARAMETER :: ns = 1000,n = 100
INTEGER :: i,j,x,y,id
REAL :: r,d,d2,temp
!
CALL RANDOM_SEED()
d = 0.0; d2 = 0.0
DO i=1,ns
x = 0; y = 0
DO j = 1,n
CALL RANDOM_NUMBER(r)
id = INT(r*4.0)
SELECT CASE(id)
CASE(0)
x = x + 1
CASE(1)
x = x - 1
CASE(2)
y = y + 1
CASE(3)
y = y - 1
END SELECT
ENDDO
temp = float(x**2+y**2)
d = d + sqrt(temp)
d2 = d2 + temp
ENDDO
d = d/float(ns); d2 = d2/float(ns)
print*,ns,n,d,d2
!
END PROGRAM RANDOM_WALKS
Non-Reversal Random Walk
SUBROUTINE NRRW
DO i=1,ns
x = 0; y = 0
PROGRAM NR_RANDOM_WALKS !(Sources acknowledged)
xp = x; yp = y
IMPLICIT NONE
INTEGER, PARAMETER :: ns = 1000,n = 100
DO j = 1,N
INTEGER :: i,j,x,y,id,xp,yp,xt,yt xt = x; yt = y
REAL :: r,d,d2,temp test = .FALSE.
LOGICAL :: test DO WHILE(.NOT.test)
! CALL RANDOM_NUMBER(r)
CALL RANDOM_SEED() id = INT(r*4.0)
d = 0.0; d2 = 0.0 IF (id == 0) THEN
CALL NRRW() x = xt + 1; y = yt
d = d/float(ns); d2 = d2/float(ns)
ELSEIF (id == 1) THEN
print*,ns,n,d,d2
! x = xt - 1; y = yt
CONTAINS ELSEIF (id == 2) THEN
y = yt + 1; x = xt
SUBROUTINE NRRW() ELSEIF (id == 3) THEN
y = yt - 1; x = xt
END PROGRAM NR_RANDOM_WALKS ENDIF
IF ((x .NE. xp).OR.(y .NE.yp)) test =.TRUE.
ENDDO
xp = xt; yp = yt
ENDDO
temp = float(x**2+y**2)
d = d + sqrt(temp)
d2 = d2 + temp
ENDDO
END SUBROUTINE NRRW
Self-avoiding Random Walk
SUBROUTINE SAW
DO i = 1,ns
lattice = 0; !Initialization
x = 0; y = 0
step = 0; terminate = .FALSE.
DO WHILE ((.NOT. terminate) .AND. (step <= n))
xt = x; yt = y
nn = lattice(x+1,y)+lattice(x-1,y) &
+lattice(x,y+1)+lattice(x,y-1)
IF (nn == 4) THEN
terminate = .TRUE.
PROGRAM SELF_AVOIDING_WALKS !Modified by VM ELSE
IMPLICIT NONE newsite = .FALSE.
INTEGER, PARAMETER :: ns = 100,n = 100 DO WHILE (.NOT. newsite)
INTEGER, DIMENSION(-n:n,-n:n) :: lattice CALL RANDOM_NUMBER(r)
INTEGER :: i,x,y,xt,yt,id,step,nn id = INT(r*4.0)
REAL :: r,d,d2,temp IF (id == 0) THEN
LOGICAL :: terminate,newsite x = xt + 1; y = yt
! ELSEIF (id == 1) THEN
CALL RANDOM_SEED() x = xt - 1; y = yt
d = 0.0; d2 = 0.0 ELSEIF (id == 2) THEN
CALL SAW() ! self avoiding walks y = yt + 1; x = xt
d = d/float(ns); d2 = d2/float(ns) ELSEIF (id == 3) THEN
print*,ns,n,d,d2 y = yt - 1; x = xt
ENDIF
CONTAINS IF (lattice(x,y) == 0) newsite = .TRUE.
ENDDO
SUBROUTINE SAW() step = step + 1; lattice(x,y) = 1
ENDIF
END PROGRAM SELF_AVOIDING_WALKS ENDDO
temp = float(x**2+y**2)
d = d + sqrt(temp); d2 = d2 + temp
ENDDO
END SUBROUTINE SAW
!

You might also like