Mean squared displacement with a random walk
12 views (last 30 days)
Show older comments
Dear,
I am working with a random walk or you can call Brownain motion in polar coordinate with Mean squared displacement (MSD). However, MSD means calculate the average of trajectory for initial and end point.
on other hand, the result must be in a smooth curve but all my results was has oscillation. What does mean wrong.
How I can change the code to have a smooth curve?
here is my code
initialX=0;
initialY=0;
X=0;
Y=0;
for i= 1:100
theta = 2*pi*randn; %I wrote like this because I need the animals
%choose any direction for whole circle (0.2pi). This only to way to
%describe the animals direction.
r=abs(randn); %I wrote the abs because I worke with the polar coordinate
%and the result in Polar coordinate always possitive.
X(i+1)=X(i)+r*cos(theta); % Polar coordinate.
Y(i+1)=Y(i)+r*sin(theta); % Polar coordinate
for j=1:1000
d1(j)=sqrt(sum(X(i)-initialX).^2+(Y(i)-initialY).^2);
end
MSD(i)=mean(d1);%calcalute the avarage for the total displacment.
plot(MSD);
title('Mean squared displacement for 100 steps');
xlabel('Number of step');
ylabel('Avarage displacement on number of steps');
end
figure;
plot(X,Y,'k');
title(' Polar coordinate 100');
Please note that I wrote the second for loop because I need calculate the realization for steps
3 Comments
Sindar
on 19 Feb 2020
1) are you sure you want a gaussian/normal/bell-curve random angle
theta = 2*pi*randn;
and not a uniform one:
theta = 2*pi*rand;
2) your j loop appears to fill d1 with 1000 identical numbers. Why?
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!