clear all; close all; clc;
figure(1)
set(gcf,'Units','normalized','Position',[0 0 1 1])
N = 100;
M = 100;
x(1,M) = 0;
y(1,M) = 0;
for n = 2:1:N
bx = randi([0,1],1,M)*2-1; % binary random number
by = randi([0,1],1,M)*2-1; % binary random number
x(n,:) = x(n-1,:) + bx;
y(n,:) = y(n-1,:) + by;
subplot(1,2,1)
plot(x(:,1),y(:,1),'k')
xlabel('x')
ylabel('y')
axis equal
set(gca,'FontSize',20)
subplot(3,2,6)
plot([0:1:n],sqrt(2*[0:1:n]),'r')
hold on
plot(sqrt(mean(x.^2+y.^2,2)),'k')
xlim([0 N])
xlabel('t')
ylabel('MSD(t)')
set(gca,'FontSize',12)
drawnow()
end
msd = mean(sqrt(2*[0;1;n]));
disp(msd);
msds = mean(sqrt(mean((x.^2+y.^2),2)));
disp(msds);
------我试过运行并修改了上面的代码,幸运的是,它非常成功......只是“msd”和“msds”上显示的值非常大差别..两者的值必须更接近或几乎相等..好吧,我用于计算两者的命令已成功用于相同的模拟,但它在一维...而且上面的代码是二维的...必须我做 ??
答案 0 :(得分:0)
第39行有拼写错误。试试:
msd = mean(sqrt(2*[0:1:n]));
而不是:
msd = mean(sqrt(2*[0;1;n]));
然后我对msd和msds有相同的值。