Question: Do not forget to submit your work to gradescope before the deadline. A Makefile is provided.Exercise 1 . ( 5 0 points ) DiffusionIn this

Do not forget to submit your work to gradescope before the deadline. A Makefile is provided.Exercise 1.(50 points) DiffusionIn this exercise, we use a 3D random walk to simulate a diffusion process.Imagine a particle starting atthe origin (0,0,0) that has equal probabilities to go in 6 possible directions - left, right, backward, forward, down, and up. For example, when the particle is at (z, y, z), with equal probability 1/6, its next location isat 1,9.2+1,9.2.9-1,2.U+1.22.9,2-1 or1-The particle will conduct the random walk for n steps. We are interested in the distribution of the final locations of particles after each takes n steps.Specifically, we would like to know the distribution of thedistance between the final location and the origin. In order to obtain this distribution, we simulate m such particles, and check the proportion of the particles that lies within rn distance from the origin, where r is a real number between 0 and 1. Note all the particles will be within a sphere with radius n since particles only move n steps and the furthest they can go is a distance n from the origin. In our simulation, we will calculatethe proportion of particles that are within rn from the origin for r =0.05,0.10,0.15,...,0.90,0.95,1.00.Below is the main) function for this program. Note how we use command line arguments. int main (int arg, char arg])if (arge |=3)printi ("Usage: (1)/(2)a n a\a", argv (0]): return 0;int n " atoi(argv (1));int n- atoi(argv [2]);srand (12345) :diffusion(n, m);return 0;We need to implement the function void diffusion (int n, int m)In this function, we need to dynamically allocate memory to represent a 3D grid where z, y.= coordinates range from -n to n. For all the possible z, y, z coordinates within the range, we save the number of particles that end up at the location (r.y,). During the simulation, if the final location of a particle is (r, y,=), the corresponding value will be incremented by 1.Generate a random number using rand()%6. If this number is 0 or 1, you should move left or right on the x-axis, respectively. If it is 2 or 3, you should move up or down on the y-axis, respectively. If it is 4 or 5, move up or down on the z-axis, respectively.In the implementation of main, we use the below function to print out results.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!