《2022年随机行走——matlab仿真 .pdf》由会员分享,可在线阅读,更多相关《2022年随机行走——matlab仿真 .pdf(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、应用物理学汪思敏 201030450333 Exercise clear;len=1;j=0;close all ;x = 0:10 ;y = repmat(0:10,11,1) ;for i = 0 : 10 plot(x,y(:,i+1) ; hold on ;endN = 500 ;x_needle = 1+8*rand(N,2) ;theta = 2*pi*rand(N,1) ;y_needle = x_needle + len*cos(theta),sin(theta) ;x1=(x_needle+y_needle)/2;a=x_needle(:,2);b=y_needle(:,2)
2、;c=x1(:,2);if(theta=pi)if(abs(c-a)=abs(floor(c)-c)&(abs(c-b)=abs(ceil(c)-c)if(floor(c)-c=0) j=j+1;endendelseif(abs(c-a)abs(ceil(c)-c)&(abs(c-b)abs(floor(c)-c) j=j+1;endendprobability=j/Nfor i = 1 : Nplot(x_needle(i,1),y_needle(i,1),x_needle(i,2),y_needle(i,2),b) ;endtitle(Needles in parallel lines)名
3、师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 4 页 - - - - - - - - - Exercise 7.2 clearN=100;M=500;re=zeros(M*3,N);for ii=1:N-1for jj=1:Mif rand (2/3)if rand(1/3) re(jj*3-1,ii+1)=re(jj*3-1,ii)+sign(rand-0.5); re(jj*3-2,ii+1)=re(jj*3-2,ii); re(jj*3,ii+1)=re(jj*3,
4、ii);else re(jj*3-2,ii+1)=re(jj*3-2,ii)+sign(rand-0.5); re(jj*3-1,ii+1)=re(jj*3-1,ii); re(jj*3,ii+1)=re(jj*3,ii);endelsere(jj*3,ii+1)=re(jj*3,ii)+sign(rand-0.5);re(jj*3-2,ii+1)=re(jj*3-2,ii);re(jj*3-1,ii+1)=re(jj*3-1,ii);endend名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - -
5、- - 第 2 页,共 4 页 - - - - - - - - - endplot(sum(re.2,1)/M)title(Random walk in three dimension)xlabel(step number (= time)ylabel()Hence t ,and the value of the proportionality constant is 0.5. Exercise 7.9 clear;D=1;pho=zeros(101,101);pho(51,1)=1;dt=0.5;dx=1;x=linspace(-50,50,101);for j=1:100for i=2:1
6、00pho(i,j+1)=pho(i,j)+D*dt/(dx2)*(pho(i+1,j)+pho(i-1,j)-2*pho(i,j);endendplot(x,pho(:,101)hold on名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 4 页 - - - - - - - - - C=1/sqrt(2*D*100*dt)*exp(-x.2/(2*sqrt(2*D*100*dt)2);plot(x,C,b)title(Diffusion in one dimension)xlabel(x)ylabel(density)名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 4 页 - - - - - - - - -