Brownian motion is the observed movement of small particles as they are randomly bombarded by the molecules of the surrounding medium. This was first observed by the biologist Robert Brown and was eventually explained by Albert Einstein, for which work he received the Nobel prize. We can simulate Brownian motion in one dimension by tossing coins. If the sequence of tosses is 1 1 0 1 1 1 0 0 1 0
0 0 1 0 1 0 0 1 0 1
then we can move are particle one unit to the right each time we see a 1, and on unit to the left each time we see a 0. This results in the new sequence 1 2 1 2 3 4 3 2 3 2
1 0 1 0 1 0 -1 0 -1 0
We haven't dispalyed the starting position (0). We can also display this graphically: *
* * *
* * * *
* * * * *
-------------*-*-*-*-*--- x = 0
* *
We can simulate Brownian motion using the computer if we have a good generator of uniformly distributed random numbers. This is what the program uni.c does. To copy uni.c to your directory, do this % cp /u/cl/doc/ma217/uni.c .
% ls uni.c
% uni.c
We copied uni.c from the directory /u/cl/doc/ma217 . Note the period (.) in the copy (cp) command. It stands for your current directory. Now type the program r1.c . Finally, compile it like this: % gcc r1.c uni.c
This compiles both your program and uni.c. The two compiled files are then linked together, and you can run them using % a.out
Recall that a.out is the default name of a compiled C program. You should get this output: 1: 0.775535
2: 0.847905
3: 0.297409
4: 0.017542
5: 0.121674
6: 0.527103
7: 0.889287
8: 0.182352
9: 0.387452
10: 0.564470
Once you have a good way of producing uniformly distributed random numbers in the range [0,1], you can compute other sequences of random numbers. For example, to get a uniformly distributed sequence of zeros and ones, use the rule: if u < 1/2
then v = 0
else v = 1
where u is a random variable uniformly distributed in the range [0,1]. To get a sequence of uniformly distributed numbers in the range [-1,+1], set v = 2u - 1
Problem set 1
Modify r1.c so that you can enter the seed value and the number of random numbers to be printed. You may want to change the output format. Recall that the seed is a long, so you need code like this: scanf("%ld", &iseed).
Test the random number generator uni.c using five "bins" --- five equal intervals which partition the unit interval. You should use your own random seed (perhaps more than once).
Devise a program which simulates random walk in one dimension. Do this by setting x = 0, then repeatedly adding uniformly distributed random numbers in the range [-1,1] to ...