【发布时间】:2015-02-02 16:55:53
【问题描述】:
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”上显示的值很大差异..两者的值必须更接近或几乎相等..好吧,我用于计算两者的命令对于相同的模拟已经成功,但它是一维的..上面的代码是二维的..什么必须我做 ??
【问题讨论】:
标签: matlab