Sie sind auf Seite 1von 7

Problem 9.

a
The python code is as follows:
import numpy a s np
import m a t p l o t l i b . p y p l o t a s p l t
b=0.8 #p r o b a b i l i t y t o go r i g h t
q =0.2 #p r o b a b i l i t y t o go l e f t
a=1 #s i z e o f each s t e p
N= [ 4 , 8 , 1 6 , 3 2 , 6 4 , 1 2 8 , 2 5 6 ] #number o f s t e p s
mean = [ ]
f o r i in N:
x=(bq ) i # u s i n g e q u a t i o n <x>=(pq )Na#
mean . append ( x )
print a v e r a g e d i s t a n c e f o r N= [ 4 , 8 , 1 6 , 3 2 , 6 4 , 1 2 8 , 2 5 6 ] i s , mean , .
mean sqrt dist =[]
f o r i in N:
x=4bq i #u s i n g e q u a t i o n <x2>=4pqNa2#
m e a n s q r t d i s t . append ( x )
print mean s q u a r e d d i s t a n c e f o r N= [ 4 , 8 , 1 6 , 3 2 , 6 4 , 1 2 8 , 2 5 6 ] i s , m e a n s q r t d i s t ,
p l t . p l o t (N, m e a n s q r t d i s t , o )
p l t . s u p t i t l e ( Dependence o f mean s q u a r e d d i s t a n c e on N )
p l t . x l a b e l ( Number o f s t e p s )
p l t . y l a b e l ( mean s q u a r e d d i s t a n c e )
p l t . show ( )

1
Result
The result obtained is average distance for N=[4,8,16,32,64,128,256] is [2.4000000000000004,
4.800000000000001, 9.600000000000001, 19.200000000000003, 38.400000000000006,
76.80000000000001, 153.60000000000002]
Mean squared distance for N=[4,8,16,32,64,128,256] is [2.5600000000000005,
5.120000000000001, 10.240000000000002, 20.480000000000004, 40.96000000000001,
81.92000000000002, 163.84000000000003] .

Figure 1: Dependence of mean squared distance on Number of steps

From the figure 1, it can be seen that there is a linear dependence of mean
squared distance on Number of steps.

Problem 9.b
The python code is as follows:
import random
from c o l l e c t i o n s import Counter
import m a t p l o t l i b . p y p l o t a s p l t
def random walk 2 ( n ) :

2
x=0
pos count =[]
neg count =[]
f o r i in range ( n ) :
dx=random . uniform ( 0 , 1 )
i f dx > 0 . 2 :
x=x+1
else :
x=x1
i f x >0:
p o s c o u n t . append ( x )
else :
n e g c o u n t . append ( x )
a=Counter ( p o s c o u n t )
b=Counter ( n e g c o u n t )
count=len ( a . k e y s ())+ len ( b . k e y s ( ) )
return count
n u m b e r o f w a l k s =1000
N= [ 4 , 8 , 1 6 , 3 2 , 6 4 , 1 2 8 , 2 5 6 ]
DN= [ ]
f o r w a l k l e n g t h in N:
d i s t i n c t l a t t i c e s i t e =0
f o r i in range ( n u m b e r o f w a l k s ) :
x=random walk 2 ( w a l k l e n g t h )
d i s t i n c t l a t t i c e s i t e+=x
mean number= d i s t i n c t l a t t i c e s i t e / n u m b e r o f w a l k s
DN. append ( mean number )
print DN
p l t . p l o t (N, DN, o )
p l t . s u p t i t l e ( Dependence o f mean number o f d i s t i n c t l a t t i c e s i t e s on N )
p l t . x l a b e l ( Number o f s t e p s )
p l t . y l a b e l ( mean number o f d i s t i n c t l a t t i c e s i t e s )
p l t . show ( )

Result
The mean number of distinct lattice sites is [3, 5, 10, 20, 39, 77, 154]. Therefore,
there is also a linear dependence of mean number of distinct lattice sites on
Number of steps as shown in figure 2 .

3
Figure 2: Dependence of Mean number of distinct lattice site on N

Problem 10.a
The python code is as follow:
import numpy a s np
import m a t p l o t l i b . p y p l o t a s p l t
import random
d e f randomWalkb ( l e n g t h ) :
steps = [ ]
x , y = 0 ,0
walkx , walky = [ x ] , [ y ]
f o r i in range ( length ) :

new = random . r a n d i n t ( 1 , 4 )
i f new == 1 :
x += 1
e l i f new == 2 :
y += 1
e l i f new ==3 :

4
x += 1
else :
y += 1
walkx . append ( x )
walky . append ( y )
r e t u r n [ walkx , walky ]
mewalk = [ ]
f o r walker in range ( 1 0 0 0 ) :
walk=randomWalkb ( 3 0 0 0 )
mewalk . append ( walk )
p r i n t l e n ( mewalk )
f o r i i n r a n g e ( l e n ( mewalk ) ) :
p l t . p l o t ( mewalk [ i ] [ 0 ] , mewalk [ i ] [ 1 ] , l a b e l =Random walk )
p l t . s c a t t e r ( mewalk [ i ] [ 0 ] , mewalk [ i ] [ 1 ] )
p l t . show ( )
For, number of walker 5 and each walker having 6 step, we can get following
shape shown in figure 3.Here, each color represent each walker.

Figure 3: Number of walke=5 and each walker has step=6

5
For, number of walker 500 and each walker having 600 step, we can get following
shape shown in figure 4 .It can be seen that the shape is still preety zigzag.

Figure 4: Number of walker=500 and each walker has step=600

For, number of walker 3000 and each walker having 1000 step, we can get
following shape shown in figure 5.It can be seen that the shape is very smooth.
It shows that with increasing number of step and number of walk, the shape of
the bee swarn gets smooth.

6
Figure 5: Number of walker=3000 and each walker has step=1000

Das könnte Ihnen auch gefallen