Help with 2d random walk

6 visualizaciones (últimos 30 días)
DDDD el 28 de Oct. de 2014
Respondida: David Sanchez el 28 de Oct. de 2014
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).

Respuestas (1)

David Sanchez
David Sanchez el 28 de Oct. de 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);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by