Just like the dterministic systems, the random systems can easily be found in our life, just like random or diffusion. In this paper, I will investigate the random walk in 1D, 2D and 3D to find the easy laws in random system. Then, I would like to find the diffusion model to have a better realize of random system.
Key Words
Random Systems; Random Walk; Diffusion
Background
In all of our work to this point we have considered systems that are deterministie. Now, we consider a class of systems in which randomness plays a central role. These are called random or stochastic systems. Typically, these system consist of a very large number of "degrees of freedom," which might be assiciated with particles of perhaps spins. Randomness can then arise in several different ways. Atypical stochastic problem is diffusion. Our goal is to constract a useful theoretical description of the random system. Since we seek average properties, we will model the deterministic process ina random one that designed to have the same average properties. Such can be modelled by what's known as a 'random work'.
1D Model
Here , we formally introduce the concept of random walk. A random walk is a mathematical object which describes a path that consists of a succession of random steps. The simplist situation involves a walker that is able to take steps of length unity along a line.
The walker begins at the origin, , and the first step is chosen at random to be either to the left or right, each with the probability 1/2. And the next step was then chosen, and again the probabilities for stepping lift or right are both 1/2.
If we want to write the codes,we can just like this:
First, we need a random number generator.
Then we should initialize an array which will hold the squared displacements at time step t.
Then loop through the desired number of walkers
Initialize the initial location of the walker to
Loop through the number bteween 0 and 1.
If , update x to , otherwise to .
Accumulate the squared displacement:
At last, normalize the squared displacement to get the mean squared displacement averaged over all of the walker: for all .
2D Model
Model one
Just like the 1D model, for the 2D model, we have two directions to walk. The walker is able to take steps of length unity along two lines. So, we can solve the problem in a lattice.
Model two
We can le the walker walk in ang way, thus it's the real 2D random walk, but not the random in a 2D lattice random walk.
For all the two models, the code we use to solve probelm just like the 1D.
3D Model
Just like the 1D model, for the 3D model, we have three directions to walk. The walker is able to take steps of length unity along three lines. So, we can solve the problem in a lattice just like body cubic.
Diffusion constant
In 1D model, if we have some walkers, and we can obtain some different runs of the walkers. The walkers move erretically, which is why this process is sometimes referred to as a drunkard's walk. Several quantitative results can be obtain from these simulations. Since a walker is as likely to step left as right, this average, whhich we denote by , must be zero.
A more interesting and informative quantive is , the average of the square of the displacement after n steps (denoted by x2ave in our rwalk routine). We see that they are well described by a straight line, that is
Where t is the time, which here is just equalto the step number; but the factor D is known as the diffusion constant.
For such a particle we know that so its distance from the origin grows linearly with time.
Thus we obtain:
Also ,this result for D can, in fact, be obtained analytically. Writing the position after n steps, , as a sum of n separate steps gives
Where there is the displacement of the ith steps. For this problem is a random variable, with with equal probabilities. We can then write
Since the steps are independent of each other,the terms with will be with equal probaility. If we average over a large number of separate walks this will leave only the terms with or . Thus we find:
Where we have used the fact that . Since n is also equal to time, this is identical to with .
Also there are many other intersting generalizations of the random-walk model.Just like we can find the diffusion constant in 2D and 3D model. Such as in 2D model, we can have and in 3D model . Like the result in 1D model, the and the .
What's more, we can investigate the result if the step length to different direction are different or the probability to different direction are different. We can find the diffusion too.
The Main Body
Code
For the random walk we can write the code just like this.
@author: RF
def __init__(self,x=0,y=0,z=0):
self.x=[x]
self.y=[y]
self.z=[z]
self.temx=0
self.temy=0
self.temz=0
self.direct=0
self.n=[0]
self.dn=0
self.squx=[0]*100
self.squy=[0]*100
self.squz=[0]*100
self.r=[0]*100
def run(self):
for n in range(1000):
s=random.randint(0,150)
if s<=25:
self.temy=self.temy+1
elif s<=50:
self.temy=self.temy-1
elif s<=75:
self.temx=self.temx-1
elif s<=100:
self.temx=self.temx+1
elif s<=125:
self.temz=self.temz+1
else:
self.temz=self.temz-1
self.dn=self.dn+1
self.x.append(self.temx)
self.y.append(self.temy)
self.z.append(self.temz)
self.n.append(self.dn)
Also we can change the code for run, then we will have the code for real random walk in 2D.
for n in range(100):
s=random.randint(0,628)
s=s/100
self.dn=self.dn+1
self.temx=self.temx+1*math.cos(s)
self.temy=self.temy+1*math.sin(s)
self.x.append(self.temx)
self.y.append(self.temy)
self.n.append(self.dn)
For the diffusion constant D, we can have the code for versus time. We just need to change the code for run from the book.
for n in range(500):
temx=0
temy=0
temz=0
for m in range(100):
s=random.randint(50,100)
if s<=25:
temy=temy+1
elif s<=50:
temy=temy-1
elif s<=75:
temx=temx-2
elif s<=100:
temx=temx+2
elif s<=125:
temz=temz+1
else:
temz=temz-1
self.squx[m]=self.squx[m]+(temx**2)/500
self.squy[m]=self.squy[m]+(temy**2)/500
self.squz[m]=self.squz[m]+(temz**2)/500
self.r[m]=self.squx[m]
if we want to change the step length or the probabilities to different directions, we can just to change the code for run.
Result
For the random walk in 1D, first we should to investigate the result for different steps.
So I chose the to plot the figure to see the random walk.
We can have a clear looking of the relationship between x and step number.
Also we want to see the randomness of random walk. So I plot some random walks together in one picture for same .
We can find that the result are different from each other, so that we are able to have that the walk are random.
For the diffusion constant D, first we can chose 500 walks and 100 step to have the average. We wil have the picture versus t.
To find the influence of the number of steps n, we change the n to 1000 to see the result.
Also I want to see the influence of the number of walks. I change number of walks to 5000.
It's easy to see that when we incress the number of walks, the result will be more likely to the idel model.
Also what will happen when we change the step length? Now, I will look forward to it.
First, I choose the step length to right is as 1.5 times and 4 times as to left.
Then I will put then together.
When incress the step length, the distance of the direction that the step length incress will be incress.
I will look forward to the influence probability. First, I choose the probability to left is as 1.5 times and 4 times as to right.
Put them together.
When change probability, the distance of the direction that the probability incress will be incress.
In addition, I can let the probability to left is as 1.5 times as to right and the step length to right is as 1.5 as to left.
As we change the step length and probability together, and same times, the walk will be random walk again.
Also for D, what will happen when change the probability of step length.
First, I chose I choose the step length to right is as 2 times and 3 times as to left.
Then put themm together.
Also I choose the probability to left is as 1.5 times and 4 times as to right.
Just like former, put them together.
We can find that, for different step length, the D onlychang by a facter but also a constant. For the different probability, the D not a constant.
For the random walk in 2D, first we should to investigate the result for different steps.
So I chose the to plot the figure to see the random walk.
We can have a clear looking of the relationship between x and y.
Also we want to see the randomness of random walk. So I plot some random walks together in one picture for same .
We can find that the result are different from each other, so that we are able to have that the walk are random.
For the diffusion constant D, first we can chose 500 walks and 100 step to have the average. We wil have the picture versus t.
To find the influence of the number of steps n, we change the n to 1000 to see the result.
Also I want to see the influence of the number of walks. I change number of walks to 5000.
It's easy to see that when we incress the number of walks, the result will be more likely to the idel model.
Also what will happen when we change the step length? Now, I will look forward to it.
First, I choose the step length to x is as 3 times as to y.
Also we can have if the step length of y is 1, 3 and 5 times of the step length of y.
When incress the step length, the distance of the direction that the step length incress will be incress.
I will look forward to the influence probability. First, I choose the probability to y is as 3 times as to x.
When change probability, the distance of the direction that the probability incress will be incress.
In addition, I can let the probability to y is as 3 times as to x and the step length to right is as 3 as to left.
As we change the step length and probability together, and same times, the walk will be random walk again.
For a real random walk in 2D.first we should to investigate the result for different steps.
So I chose the to plot the figure to see the random walk.
We can have a clear looking of the relationship between x and step number.
Also we want to see the randomness of random walk. So I plot some random walks together in one picture for same .
We can find that the result are different from each other, so that we are able to have that the walk are random.
For the random walk in 3D, first we should to investigate the result for different steps.
So I chose the to plot the figure to see the random walk.
We can have a clear looking of the relationship between x, y and z.
For the diffusion constant D, first we can chose 500 walks and 100 step to have the average. We wil have the picture versus t.
To find the influence of the number of steps n, we change the n to 1000 to see the result.
Also I want to see the influence of the number of walks. I change number of walks to 5000.
It's easy to see that when we incress the number of walks, the result will be more likely to the idel model.
Conclusion
For random walk, we can not to clone two identical random walk pattern, which means this process is absolutely random. Also it's easy to know that for the average is zeor in all 1,2,3 D and the for the average is propotional to step number in all 1,2,3 D. Also for the diffusion constant D, when we change the step length in different direction, the D also be a constant in all 1,2,3 D, but if we change the probability in different direction, D will not be a constant.
In fact, the conservation of any non - regular Walker corresponds to a law of diffusion. Although any single step does not obey the law of diffusion, it is possible to accurately predict the irregular walk if you wait long enough. Through the program to simulate the random walk behavior of a large number of particles, we can intuitively understand the characteristics of the diffusion phenomenon, and realize that the diffusion phenomenon has the randomness of the local motion and the certainty of the macroscopic quantity. Also, we can use random work to study the problem in daily life.
Thanks For
Nicholas J.Giordano;Hisao Nakanishi,Computational Physics,second edition,Pearson Education.2007.
Wikipedia.
顾昌鑫等.计算物理学.复旦大学出版社,2010.
Tiger Zhou for his conduction in cluster growth model.
Pólya's Random Walk Constants, Mathworld.wolfram.com. Retrieved 2016.