📄 brownian.m
字号:
%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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -