In [1]:
# import modules
import numpy as np
import matplotlib.pyplot as plt 
%matplotlib inline

# for prestty plotting
import seaborn as sns
sns.set()

# import the pboc utils for plotting 
import pboc_utils as pboc

define some parameters for our integration

In [2]:
# hopping rate 
k = 1

# time step
dt = 0.1 

# parameters for the array
n_boxes = 40
n_steps = 100 

# 2D array to store probabilities
p = np.zeros([n_boxes, n_steps])

# find the middle box
n_center = int(n_boxes / 2)

p[n_center,0] = 1

do the integration

In [3]:
# loop through time
for t in range(1, n_steps): 
    
    # loop through boxes
    for b in range(1,n_boxes-1): 
        
        # update probability for the interior boxes
        p[b,t] = p[b,t-1] + k*dt*p[b-1,t-1] + k*dt*p[b+1,t-1] - 2*k*dt*p[b,t-1]
        
    # update probability for the left edge box
    p[0,t] = p[0,t-1] + k*dt*p[1,t-1] - k*dt*p[0,t-1]

    # update probability for the right edge box
    p[-1,t] = p[-1,t-1] + k*dt*p[-2,t-1] - k*dt*p[-1,t-1]
In [4]:
# plot the result
pboc.bar_plot(p, n_slices = 6, dy=dt, x_label="box number", y_label="time")
Out[4]:
(<Figure size 720x576 with 1 Axes>,
 <matplotlib.axes._subplots.Axes3DSubplot at 0x1c21f61080>)
In [5]:
# number of time steps
n_steps = 1000

# 2D array for storing probabilities
p = np.zeros([n_boxes, n_steps])

# specify fluorescence for time step
p[:,0] = 1

# boxes to photobleach
n_bleach = 10 
start = n_center - int(n_bleach/2) 
end = n_center + int(n_bleach/2)
p[start:end,0] = 0

# normalize probabilty after photobleach
p[:,0] = p[:,0] / np.sum(p[:,0])
In [6]:
# loop through time
for t in range(1, n_steps): 
    
    # loop through boxes
    for b in range(1,n_boxes-1): 
        
        # update probability for the interior boxes
        p[b,t] = p[b,t-1] + k*dt*p[b-1,t-1] + k*dt*p[b+1,t-1] - 2*k*dt*p[b,t-1]
        
    # update probability for the left edge box
    p[0,t] = p[0,t-1] + k*dt*p[1,t-1] - k*dt*p[0,t-1]

    # update probability for the right edge box
    p[-1,t] = p[-1,t-1] + k*dt*p[-2,t-1] - k*dt*p[-1,t-1]
In [7]:
pboc.bar_plot(p, n_slices = 6, dy=dt, x_label="box number", y_label="time")
Out[7]:
(<Figure size 720x576 with 1 Axes>,
 <matplotlib.axes._subplots.Axes3DSubplot at 0x1c229bb2e8>)