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...
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
文章来源: yunyaniu.blog.csdn.net,作者:一个处女座的程序猿,版权归原作者所有,如需转载,请联系作者。
原文链接:yunyaniu.blog.csdn.net/article/details/83758429
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)