天天看點

Algorithm之MC:基于Matlab實作通過蒙特卡洛方法模拟二維布朗運動

輸出結果

基于Matlab實作通過蒙特卡洛方法模拟二維布朗運動

Algorithm之MC:基于Matlab實作通過蒙特卡洛方法模拟二維布朗運動

設計代碼

%基于Matlab實作通過蒙特卡洛方法模拟二維布朗運動

function [x,y,m,n]=br2(x0,xf,y0,yf,h)

x=x0:h:xf;

y=y0:h:yf;

a=randn(size(x));

b=randn(size(y));

m(1)=0;

n(1)=0;

for k=1:length(x)-1;

m(k+1)=m(k)+a(k);

n(k+1)=n(k)+b(k);

end;

%再在指令視窗鍵入

x0=0;

xf=10;

h=0.01;

y0=0;

yf=10;

[x,y,m,n]=br2(x0,xf,y0,yf,h);

plot(m,n)

xlabel('m');

ylabel('n')

繼續閱讀