# 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
# 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
# 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]
# plot the result
pboc.bar_plot(p, n_slices = 6, dy=dt, x_label="box number", y_label="time")
# 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])
# 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]
pboc.bar_plot(p, n_slices = 6, dy=dt, x_label="box number", y_label="time")