0

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)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Omid Erfanmanesh
  • 547
  • 1
  • 7
  • 29

1 Answers1

1

I believe that you still want to write diff_sq = diff**2, as indicated in "diff squared".

Going from n=2 to n=3 only changes the way one computes distances, as you have done by adding the zdata vector into your square root.

  • However, you might need to use the `np.diff` function on the coordinates before computing distances, depending on what you are trying to achieve. – Baptiste Prevot Sep 21 '20 at 10:15