Python Please Simulating a random walk in two dimensions. For this part, you will use a two-dimensional...

70.2K

Verified Solution

Question

Programming

Python Please

Simulating a random walk in two dimensions.

For this part, you will use a two-dimensional grid where the xaxis goes from -50 to +50 and the y axis also goes from -50 to +50.The particle will start at the middle of the left edge (x, y) =(−50,0), and we’ll put the outlet/absorber in the middle of theright edge (x, y) = (+50,0). Again, the particle will diffusearound randomly between these points and when the absorbing pointat (x, y) = (+50,0) is reached, the simulation ends. At each timestep, the particle can move one step on the grid and yoursimulation will update the particle’s x and y positionsaccordingly. Here are the rules for the random walk:

At each time step:

1. If the particle is not at an edge, it can take a step of onegrid spacing in any of four directions: ±x, ±y; these should all beequally probable.

2. If the particle is at one of the edges, but not at theabsorber, it cannot pass out of the box. It should have a 50%probability of taking a step perpendicularly away from the wall,and a 25% chance of stepping in either of the directions along thewall.

3. If the particle is at a corner, it has a 50% chance of goingin either of the two directions along the walls.

4. If the particle touches the absorbing point at (x, y) =(+50,0), the random walk ends.

Part 2. Simulate a single 2d random walk until absorption.

D. (20 pts) Write a program that executes one ‘walk’ andcalculates the number of steps the particle takes before beingabsorbed – the residence time of our two-dimensional lake for thattracer. You will be assessed on whether you have correctlyimplemented the walking rules above.

E. (10 pts) Make a plot of the trajectory taken by the particle(positions in x,y).

a. Label the x and y axes appropriately, and give the plot atitle

b. Indicate the starting position with a black asterisk and theend position with a red asterisk.

F. (5 pts) Print the time (i.e. number of steps) it took for theparticle to be absorbed.

Answer & Explanation Solved by verified expert
3.9 Ratings (472 Votes)
Programimport randomimport pandas as pdimport matplotlibpyplot as pltforgraph pdDataFramecolumns X Yx y 46 0 Input the starting point herexlist xylist ywhile x 45 or y 0 Change Value of x and y according to where you want the absorbtion point to be if x in range50 50 and y in range50 50 a b    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students