I am ganna to use Mean square displacement (MSD) for 3-dim matrix. This solution https://stackoverflow.com/a/31266574/4025749 calculates MSD for (x,y) but I have a matrix with (x,y,z). Wikipedia says:
Derivation for n-dimensions:
MSD=2nDt.
and this code is used for n = 2
:
import numpy as np
r = np.sqrt(xdata**2 + ydata**2)
diff = np.diff(r) #this calculates r(t + dt) - r(t)
diff_sq = diff**2
MSD = np.mean(diff_sq)
So, If I want to exploit this code for n = 3
, Can I change it to below:
import numpy as np
r = np.sqrt(xdata**2 + ydata**2 + zdata**2)
diff = np.diff(r) #this calculates r(t + dt) - r(t)
diff_sq = diff**3
MSD = np.mean(diff_sq)