Help with 2d random walk
1 回表示 (過去 30 日間)
古いコメントを表示
A particle moving in a sheet where -1<y<1 and 0<x<5. It will start at x=0 and between -0.5<y<0.5. After each step, it will move a distance defined by d=0.2*log(rand()) and a random angle from –pi/4 to pi/4. Plot a sample movement. Find after 1000 iterations how many particles make it to the end of the sheet (ie. X>5).
回答 (1 件)
David Sanchez
2014 年 10 月 28 日
This may be of help:
% Initial position
x = 0;
y = 0;
for k = 1:1000
% -1<y<1 and 0<x<5.
d = 0.2*log(rand);
% random angle between –pi/4 to pi/4
% Generate values from the uniform distribution on the interval [a,b]:
a = -pi/4;
b = pi/4;
r = a + (b-a)*rand;
% Position:
x = x + d*cos(r);
y = y + d*sin(r);
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!