Matlab:利用Matlab编程实现模拟分子布朗运动的动画展示

Matlab:利用Matlab编程实现模拟分子布朗运动的动画展示


输出结果

实现代码

%Brownian motion
clf;
n=20;
s=0.02;
x = rand(n,1)-0.5;
y = rand(n,1)-0.5;
h = plot(x,y,'.');
axis([-1 1 -1 1])
axis square
grid off
set(h,'EraseMode','xor','MarkerSize',18)
grid on;
title('Press Ctl-C to stop');
while 1
 drawnow
 x = x + s*randn(n,1);
 y = y + s*randn(n,1);
 set(h,'XData',x,'YData',y)
end
clear;clc;

%Initializetherandngenerator
randn('state',1)

%SettheparameterHandthesamplelength
H=0.7;lg=10000;
%Generateandplotwavelet-basedfBmforH=0.7
fBm=wfbm(H,lg);

n=0:10;
dt=2.^n;
v=zeros(1,length(n));
fori=1:11
    d=fBm(1+dt(i):end)-fBm(1:end-dt(i));
    v(i)=sum(d.^2)./(length(d)-1);
    cleard;
end
p=polyfit(log(dt),log(v),1);

loglog(dt,v,'ko');
holdon;

sH=p(1)./2;
ch=exp(p(2));

plot(dt,ch.*dt.^(2.*sH),'b','LineWidth',1);

%%
clc;
clearvars-exceptchsH;
mch=ch;
msH=sH;
clearchsH;

%Initializetherandngenerator
randn('state',1)

%SettheparameterHandthesamplelength
H=0.7;lg=10000;
fBm=fbm1d(H,lg);

n=0:10;
dt=2.^n;
v=zeros(1,length(n));
fori=1:11
    d=fBm(1+dt(i):end)-fBm(1:end-dt(i));
    v(i)=sum(d.^2)./(length(d)-1);
    cleard;
end
p=polyfit(log(dt./lg),log(v),1);

holdon;
loglog(dt,v,'ks');
sH=p(1)./2;
ch=exp(p(2));

plot(dt,ch.*(dt./lg).^(2.*sH),'r','LineWidth',1);

legend('matlab',strcat('Var=',num2str(mch),'*dt^{2.*',num2str(msH),'}'),'KB',strcat('Var=',num2str
(ch),'*dt^{2.*',num2str(sH),'}'),'Location','SouthEast');
saveas(gcf,'test1.jpg');

相关文章
Fractional Brownian motion generator

分数布朗运动及其模拟PDF参考文件

(0)

相关推荐