Exercise 2
Consider two-dimensional random walks with initial positions x = 0 and y = 0 (at t = 0), where a step of length dstep (for a given dstep) with a random direction is realized during a time interval tstep (for a given tstep). Be (x,y) the position after Nstep steps (which corresponds to the time t = tstep × Nstep). This position is referred to as final position.
Write the program to generate Nsim walks, where each walk consists of Nstep steps, and determine the r-distribution, with r being the distance from the origin of the final position. The r-distribution should be given (in the program) in terms of the two tables rmi[i] and phi[i], in the same way as explained for a x-distribution here. One should choose appropriate values for rmin and rmax. The r-distribution should coincide (approximately) with the distribution obtained from pDE2 (the solution of the diffusion equation at two dimensions), so compute as well that distribution, using the table fun[i] for the latter. Print rmi[i], phi[i], fun[i] to standard output. So when executing the program, we should get three columns, representing xmi[i], phi[i], fun[i].
Use Nsim = 10000, Nstep = 200, xstep = ystep= 1, tstep = 1, Nsub = 15. Compute the diffusion coefficient D, needed to compute pDE2 .
For a possible graphical representation of the results, see here.
In case of problems in understanding basic notions of the programming langage C: see
C tutorial
The solution of this exercise can be found here