I did these so far:
EDIT—————
steps=@ (m) 2*randi([0,1],[1,m])-1;
Walk1D =@ (n) [0,cumsum(steps(n))];
findend=@ (x) x(end);
LastPoint1D=@(n) findend(Walk1D(n));
nsteps=200;
nsq=floor(sqrt(nsteps));
MeanSquareDistance1D= @ (n,m) m.*sum((LastPoint1D(n)).^2)./m;
r2D=MeanSquareDistance1D(100,1000)
data=[ ];
for i=10:20:90
data=[data; i , MeanSquareDistance1D(i,2000)]
end
The only problem now,is that the 2nd column of “data” must give me values around
10
30
50
70
90
but not exactly.Only approximately.For example ,the “data” must be:
10 10.184
30 27.51
50 50.306
70 68.394
90 90.414
Sth is wrong with the sum maybe?
From your code I guess you want to calculate the mean squared distance for a 1D random walk.
The mean squared distance at lag
ttis the average squared difference between two positions along the random walk separated byttsteps. I assume thatdatashould be an array where the first column isttand the second column the corresponding mean squared distance, and where there is an additional parameter that indicates the total number of steps in your random walk.Here’s how I’d calculate
data