Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The motion of a kinesin motor protein on a microtubule can be thought of as a on

ID: 3783088 • Letter: T

Question

The motion of a kinesin motor protein on a microtubule can be thought of as a one-dimensional random walk, where at each step of unit length, the protein either goes forward with probability p or reverse with probability 1 - p. Write a function that accepts values of p and number of steps N and returns the position x of a random walker after N steps, starting at the origin. Write a driver routine that calls this function 1000 times and stores the end positions in an array. Plot the distribution of end points in the form of a normalized histogram for N = 200 and p = 0.5, 0.6, 0.7. What do you observe? For a large number of steps, the distribution of end points should be described by a Gaussian distribution P(x) = exp [(x - x_0)^2/2 sigma^2]/squareroot 2 pi sigma^2. Fit P(x) to the three distributions you computed in (c), report the fit values for x_0 and sigma, and compare to the expected values from theory.

Explanation / Answer

import numpy
import pylab      

def RandomWalk(N,p):
  
return numpy.cumsum(numpy.random.uniform(-p,p,(N,1)))

def PlotRandomWalkX(N):
"""
Plot X for one-dimensional random walk
"""
X = RandomWalk(N,1)
pylab.plot(X)
pylab.show()

  
def DriverRoutine(N=1000,p):
"""
Returns a list of endpoints of N random walks of length 1.
  
return sum(numpy.random.uniform(-p,p,(1,N,1)))

def PlotEndpoints(N=200,d):
"""
Plot endpoints of random walks.
  
"""
X, Y = numpy.transpose(DriverRoutine(N,0.5))
pylab.figure(figsize=(8,8))
pylab.plot(X,Y,'k.')
pylab.axis('equal')
pylab.show()
A, B = numpy.transpose(DriverRoutine(N,0.6))
pylab.figure(figsize=(8,8))
pylab.plot(X,Y,'k.')
pylab.axis('equal')
pylab.show()
   M, N = numpy.transpose(DriverRoutine(N,0.7))
pylab.figure(figsize=(8,8))
pylab.plot(X,Y,'k.')
pylab.axis('equal')
pylab.show()
  
def GaussianPlot(N=200,bins=50):
"""
Compares the histogram of random walks with the normal distribution
predicted by the central limit theorem.
#
(1) Plots a histogram rho(x) of the probability that a random walk
with N has endpoint X-coordinate at position x.
Uses pylab.hist(X, bins=bins, normed=1) to produce the histogram
#
(2) Calculates the RMS stepsize sigma for a random walk of length N
(with each step uniform in [-1/2,1/2]
Plots rho = (1/(sqrt(2 pi) sigma)) exp(-x**2/(2 sigma**2))
for -3 sigma < x < 3 sigma on the same plot (i.e., before pylab.show).
Hint: Create x using arange. Squaring, exponentials, and other operations
can be performed on whole arrays, so typing in the formula for rho will
work without looping over indices, except sqrt, pi, and exp need to be
from the appropriate library (pylab, numpy, ...)
"""
X = Endpoints(N,0.5)[:,0]
pylab.hist(X, bins=bins, normed=1)
#
sigma = numpy.sqrt(N/12.)
x = numpy.arange(-3*sigma,3*sigma,sigma/bins)
rho = (1/(numpy.sqrt(2*numpy.pi)*sigma))*numpy.exp(-x**2/(2*sigma**2))
pylab.plot(x, rho, "k-")
pylab.show()
  
   Y = Endpoints(N,0.6)[:,0]
pylab.hist(X, bins=bins, normed=1)
#
sigma = numpy.sqrt(N/12.)
x = numpy.arange(-3*sigma,3*sigma,sigma/bins)
rho = (1/(numpy.sqrt(2*numpy.pi)*sigma))*numpy.exp(-x**2/(2*sigma**2))
pylab.plot(x, rho, "k-")
pylab.show()
  
   X = Endpoints(N,0.7)[:,0]
pylab.hist(X, bins=bins, normed=1)
#
sigma = numpy.sqrt(N/12.)
x = numpy.arange(-3*sigma,3*sigma,sigma/bins)
rho = (1/(numpy.sqrt(2*numpy.pi)*sigma))*numpy.exp(-x**2/(2*sigma**2))
pylab.plot(x, rho, "k-")
pylab.show()

(a) Run PlotRandomWalkX.

(b) Run DriverRoutine.

(c) Run  PlotEndpoints.

(d) Run GaussianPlot