Question: BioE 021 SPRING 2019 Home Work 1 Due: March 5, 3.00 pm PST 1. (20 pts) Docs a random walker ever get back home? Use
BioE 021 SPRING 2019 Home Work 1 Due: March 5, 3.00 pm PST 1. (20 pts) Docs a random walker ever get back home? Use the editor of your choice to create a file HW1 PROBLEM1 py Consider a random walker who starts out at square 0 and randomly takes steps that can be described as forward (+1) or backward (1). An interesting question is what fraction of such random walkers ever get back home (square 0) in some specific number of steps 43 2 1 0 1 234 To analyze this problem, you will write a Python program to do what is called a Monte Carlo simulation of a 1-dimensional random walker taking 10000 steps. We'll do 100 Monte Carlo trials so we can get good statistical averages. Note that since Python 2.7 has integer division. If you want to make sure that division is always float based, you can use the command from future import division (a) Use the help in Python and write down what the following lines do: (0) from random import choice (i) point+-choicel(-1.1)) (ili) break Enter the following code into your file and run it. You will get some errors - make sure the errors are corrected in your file. (b) from future import division from random import choice trials-100 steps- 10000 got home-0 for i in range(trials) point-0 # set point-# for step in range(steps) point+choice((-1,1) f point got home+ = 1 breakd print "Fraction that got home-4 % (go-home/trials) MacBook (e) Change the number of trials from 10 to 100 in steps of 10 and rerun. What is your result for each of these trials
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
