Biophysics

Very Tiny Mini-Project: Random Walks on a Circle

Our project strives to identify the number of steps taken for a mover to arrive at a certain point when traveling in random walks in a circle. There is a 50% chance to move forward, and a 50% chance to move backwards. The input for the function would be the starting position of the mover, the final point you are aiming to reach, and the length of the circle. The output would just be the number of random walks needed to arrive at the end point on the circle you chose. Our initial general idea for the code was that we would use random walks as we learned in class, but make it into a circle by stating that when the point is greater than the length of the circle, the position would go back to 1 and start from the beginning. For each time the code runs, the count increases by one. Ultimately, the count would be the total number of steps the mover took to arrive at its end point, which is what we are trying to find.


Code:

import random as random

import matplotlib as plt

def randWalk(mover, endPoint, length):

count = 0

steps = [-1,1]


while(mover != endPoint):

if(mover == length+1):

mover = 1

if(mover == -1): mover = length-1

mover += random.choice(steps)

count = count + 1

return count

print(randWalk(89, 6, 176))

Graphing an Example data

xplots = []

for i in range(100):

m = randWalk(89,6,176)

xplots.append(m)


xplotsarray = np.array(xplots)


plt.plot(range(100), xplotsarray)

plt.xlabel('Trials')

plt.ylabel('Number of Steps')

plt.title('Number of Steps for randWalk(89,6,176)')