Create a MatLab code that solves the following problem: Consider a 2D problem that…
- User
Create a MatLab code that solves the following problem:
Consider a 2D problem that models a pipe. In the y-direction, there is a finite width that can be specified by the user. In the x-direction, the system is not bounded. Start a random walker at the origin in the x-direction, and in the middle of the pipe along the width of the pipe in the y- direction. The random walker can only step between vertices on a regular square grid. The spacing between vertices is called the “lattice constant”. At each time step, the random walker can wait in its current location with probability pw and with 1 − pw probability make a step. The step can be to the right, up, left, down, with probabilities of ¼ for each direction. Assigning equal probabilities for each possible direction indicates that the material has isotropic transport properties. Use reflective boundary conditions in the y-direction at the edge of the pipe. The lattice constant, a, that gives the length of a step when the walker moves, and the time, 𝜏, for each time step must be set. In this first problem use pw = 0. Simulate the random walk as just described. In this example, set the width of the pipe to be 5 mm and set 𝑎 = 0.01 mm
- Assistant
Here is a possible MatLab code to simulate the random walk in the given problem:
matlab - User
Note the two formulas: 〈𝑅^2 (𝑛)〉 = 𝑎 ^2 𝑛 and 〈𝑅^2 (𝑡)〉 = 𝐷𝑡. The first formula relates the mean squared displacement over many unrestricted random walks directly in terms of the number of random walk steps, given by 𝑛. The second formula expresses the mean displacement of a particle that is unrestricted in terms of continuous time, where it can be assumed that 𝑡 = 𝜏𝑛. Express the diffusion constant in terms of the model parameters {a, 𝜏}
- Assistant
To express the diffusion constant in terms of the model parameters {a, 𝜏}, we can use the formula 〈𝑅^2 (𝑡)〉 = 𝐷𝑡, where 〈𝑅^2 (𝑡)〉 is the mean squared displacement at time 𝑡 and 𝐷 is the diffusion constant.
In the given problem, the random walker moves a distance of 𝑎 at each lattice point and 𝜏 is the time step. Therefore, the time in the continuous model is given by 𝑡 = 𝜏𝑛, where 𝑛 is the number of random walk steps.
If we substitute 𝑡 = 𝜏𝑛 into the formula 〈𝑅^2 (𝑡)〉 = 𝐷𝑡, we get 〈𝑅^2 (𝑛)〉 = 𝐷𝜏𝑛.
Comparing the above equation to the first formula 〈𝑅^2 (𝑛)〉 = 𝑎^2𝑛, we can see that 𝐷𝜏 = 𝑎^2.
Therefore, the diffusion constant 𝐷 can be expressed in terms of the model parameters {a, 𝜏} as 𝐷 = 𝑎^2 / 𝜏.
- User
Modify the MatLab code using these steps:
- Visualize the random walk trajectories
- In the x-direction, calculate the mean squared displacement as a function of number of steps.
- In the y-direction, calculate the mean squared displacement as a function of number of steps.
- For 1,000,000 walks, plot the histogram of locations of the random walker in the x-direction after 100, 1000, 10000, 100000, 1000000 steps.
- For 1,000,000 walks, plot the histogram of locations of the random walker in the y-direction after 100, 1000, 10000, 100000, 1000000 steps.
- In order to obtain a diffusion constant of 10^7 𝑐𝑚^2 /𝑠𝑒𝑐, what should the average time per step be (given by 𝜏) in units of seconds.
- Working in the x-direction only, find the diffusion constant, D by taking the slope of the mean squared displacement as a function of time
- Assistant