Help with 2d random walk
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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).
Réponses (1)
David Sanchez
le 28 Oct 2014
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 commentaires
Voir également
Catégories
En savoir plus sur Random Number Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!