PDA

查看完整版本 : 将地图命令和其他命令从Mathematica转换为MATLAB


poster
2019-12-14, 20:13
到目前为止,我已经做到了:

编辑 - - - - - - - -

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 现在唯一的问题是,“数据”的第二列必须给我值

10 30 50 70 90 但不完全是。仅是近似值。例如,“数据”必须为:

10 10.184 30 27.51 50 50.306 70 68.394 90 90.414 这可能是某事不对吗?



回答:

根据您的代码,我想您想计算一维随机游走的均方距离。

滞后tt处的均方距离是沿着tt间隔的随机游走的两个位置之间的均方差。我假设data应该是一个数组,其中第一列是tt ,第二列是对应的均方根距离,并且还有一个附加参数指示随机游走的总步数。

这是我计算data

%# define parameters nSteps = 2000; listOfLags = 10:20:90; %# must be 1-by-n vector %# create random walk %# steps can be +1 or -1, add all of them via cumsum randomWalk = cumsum(randi([0 2],nSteps)-1); %# calculate msd for the desired lags %# use a loop for readability nLags = length(listOfLags); data = zeros(nLags,2); data(:,1) = listOfLags; for lag = listOfLags %# lag takes on every lag value, so use logical indexing to find %# which lag (in terms of entry into data) we're currently working on %# This line corresponds to %# 1. get all distances traveled within a duration of `lag` %# vectorOfDistances = randomWalk(lag+1:end) - randomWalk(1:nSteps-lag) %# ie the first element is randomWalk(lag+1)-randomWalk(1) %# 2. square all: (vectorOfDistances).^2 %# 3. average all squared distances data(listOfLags==lag,2) = mean( (randomWalk(lag+1:end) - randomWalk(1:end-lag)).^2); end %# plot the results plot(data(:,1),data(:,2),'.') xlabel('lag'),ylabel('mean squared displacement')

更多&回答... (https://stackoverflow.com/questions/5032029)