In [15]:
import numpy as np
import matplotlib.pyplot as plt
def Deff_calc(x,y,t):
SD = np.zeros(len(x) - 1)
MSD = np.zeros(len(x) - 1)
D_eff = np.zeros(len(x) - 1)
i = 1
while i <= (len(x) - 1):
SD[i-1] = (abs(x[0]-x[i]) ** 2 + abs(y[0]-y[i]) ** 2)
total_SD = 0
p = i
while p >= 1:
total_SD = total_SD + SD[p-1]
p -= 1
MSD[i-1] = total_SD
D_eff[i-1] = MSD[i-1]/4/t[i]
i += 1
print(SD)
print(MSD)
print(D_eff)
fig = plt.figure()
axes = fig.add_subplot(211)
plt.xlabel("time")
plt.ylabel("MSD")
plt.title("MSD vs. time")
axes.plot(t[1:len(t)],MSD)
plt.tight_layout()
axes2 = fig.add_subplot(212)
plt.xlabel("time")
plt.ylabel("D_eff")
plt.title("D_eff vs. time")
axes2.plot(t[1:len(t)],D_eff)
plt.tight_layout()
plt.show()
Deff_calc(np.array([0,-3.00,-0.5,-3.00,2.00,-2.50,2.50]), np.array([0,2.50,3.50,-4.0,0.00,-0.50,2.50]), np.array([0,1,2,3,4,5,6]))