Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 将地图命令和其他命令从Mathematica转换为MATLAB

到目前为止,我已经做到了:

编辑 - - - - - - - -

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')

更多&回答...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:13


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.