Random Walks

Introduction

In this assigment, we will take a look at and analyze two and three-dimensional random walks. Random walks describe physical processes such as the movement of particles through space.

Method

Unlike nature, computers can't truly generate totally 'random' numbers. We can use functions in C++ to try to generate a few random numbers. A few functions are the rand() and drand48() functions in C++. Using these functions require a 'seed' value, which the function takes in to generate random numbers each time. One way of doing this is using the srand48(time(NULL))[1] function, which uses the current time as a seed value to start randomizing numbers so that each time a program is run, we get new random results.

To plot a random walk, we write a program to generate random numbers and plot each point as a vector pointing to each successive vector as a path. This will be done in 2D on the xy-plane and in 3D on the xyz-plane. Then, we analyze the results of the graph by curve fitting.

Implementation

C++ files: 2D Random Walk, 3D Random Walk

The drand48() function generates pseudo-random numbers with 48-bit integer arithmetic. This was used to generate random numbers over the interval [-0.5,0.5]. We want an equal probability of the next step to move left, right, up, or down, so we multiply the interval by for random walks in two dimensions and for three dimensions[2]. Since each random number point represents a vector position, we can obtain the distance with . The 3D random walk program is identical to the 2D one, with the added variable of z.

Results and Graphical Analysis

Gnuplot was used to plot the following random walk graphs from the output files generated by the program. The graphs below show results for 100 and 1000 steps in both 2D and 3D.

Figure 1: 2D random walk at 100 steps

Figure 2: 2D random walk at 1000 steps



Figure 3: 3D random walk at 100 steps

Figure 4: 3D random walk at 1000 steps


The next set of graphs plot the distance traveled from the origin versus the number of steps taken. These examples were generated using 100 steps from the 2D and 3D random walk programs. Then, we plot the log of both values to obtain a linear slope fit.

Figure 6: Log-log fit of distance traveled vs. number of steps in 2D

Figure 8: Log-log fit of distance traveled vs. number of steps in 3D


The graph of f(x) = x/2 was plotted on both the 2D and 3D plots to compare the slope, which is expected to be 0.5[1]. As we can see in both graphs, the fitting of the plot does seem to conform to a slope of 0.5. Note also how the values tend to bunch up in the top right corner. This explains that as more steps are taken, the distance from the origin doesn't change much because the numbers generated are so random that eventually the distance from the origin between steps will tend to average out. At 1000 steps, it can be predicted that there are more cluttered points near the top right of the graph because there are more steps.

Conclusion

,

This assignment allowed us to simulate random walks of nature using deterministic computational values and this does show that it may be a valid representation of natural random walks, according to what the graphs show in the analysis. The seed value we used comes from a constant based on the current time and that looks like it has been reliable in generating random values each time the program is run. However, units of time are 'fixed', as in there will always be 60 seconds in a minute and 60 minutes in an hour, and etc, so there may be a case where we'll replicate similar patterns because of the repetition of the units of time.

References

[1] David Yevick "A First Course in Computational Physics and Object-Oriented Programming with C++", Cambridge University Press 2005, page 60.
[2] PHYS 305 Assignment #5. Varner, Gary.