brownian.m
来自「一些常被用于教学或者参考的概率论的实例的源代码」· M 代码 · 共 28 行
M
28 行
%brownian.m/created by PJNahin for "Duelling Idiots"(3/8/99)
%This m-file simulates Brownian motion (a random walk by a particle
%suspended in a fluid and being hit by molecules). At successive
%increments of time the particle performs independent motions of random
%length, uniform from -1 to 1 (in arbitrary units) in both the x and the y
%directions. The walk duration (the total number of steps, where a 'step'
%is a delta-x and a delta-y *pair*) is defined by the user. A walk always
%starts at the origin.
%
%
n=input ('Walk duration (in steps)? ');
rand('seed',100*sum(clock))
clear xpos
clear ypos
xpos(1)=0;
ypos(1)=0;
for i=2:n
deltax=-1+2*rand;
deltay=-1+2*rand;
xpos(i)=xpos(i-1)+deltax;
ypos(i)=ypos(i-1)+deltay;
end
plot(xpos,ypos)
xlabel('x direction')
ylabel('y direction')
title('Fig.19.2 - Two-Dimensional Brownian Motion')
figure(1)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?