Bias random walk under gravity, how to count how many ‘particles’ end in the same y column (and stack on top of each other)?

1 vue (au cours des 30 derniers jours)
I am trying to simulate a biased 2d random walk in a 99 x 99 unit domain. I have created a function that generates N particles to do a random walk, 1 at a time. I can't get the particles to stick once they have either reached the bottom row or an occupied square.
I have tracked the end location of each particle ('result'). However, I would like to keep the particle in the end position (which is when y=99). When the new particle is generated the end position should be when y=99 OR when a particle lands on top of the end location of the previous particle.
Can anyone please point me in the direction to achieve this?
At the moment my code stops the particle when y=99 but does not consider if it is landing on top of another particle (ie.if there is already a particle at (50,99) the new particle should stop at (50,98) not (50,99))
function [result]=random_walk_gravity(N,s,w,e)
%N (the number of particles), and s, w, e (the probabilities of moving south, west and east).
result = zeros(1,N);
for k=1:N
%start particle i at x0, y0
%In this case, all particles will start in column 50 in the top row
%step with stepsize 1 either South, West or East
%sample u(0,1) with the equal probability of moving in the east, west or
%south direction
i=1;
%initital postions
y(i)=1;
x(i)=50;
%generate random number between 0 and 1, N times
u=rand();
while y(i)<99 %we want it to stop at y=99 and look at the x-value
if (0<=u)&&(u<=e) && (x(i)<99) %Check that the x position is less than 99
%Move east, therefore xposition is increased by 1 unit
x(i+1)= x(i)+1;
y(i+1)= y(i);
i=i+1;
u=rand();
elseif (0<=u)&&(u<=e) && (x(i)>=99) %Check if the x position is greater than or equal to 99
%particle hits the side boundary it moves back in the direction
%it came from (west)
x(i+1)= x(i)-1;
y(i+1)= y(i);
i=i+1;
u=rand();
elseif (e<u)&&(u<=(e+w))&& (x(i)>0) %Check that the x position is greater than 0
%Move west, therefore xposition is increased by 1 unit
x(i+1)= x(i)-1;
y(i+1)= y(i);
i=i+1;
u=rand();
elseif (e<u)&&(u<=(e+w))&& (x(i)<0)
%Check if the x position is less than or equal to 0
%particle hits the side boundary it moves back in the direction
%it came from (east)
x(i+1)= x(i)+1;
y(i+1)= y(i);
i=i+1;
u=rand();
else %Move south, therefore yposition is increased by 1 unit
x(i+1)= x(i);
y(i+1)= y(i)+1;
i=i+1;
u=rand();
end
end
result(k) = x(i);
histogram(result)
end
  1 commentaire
Walter Roberson
Walter Roberson le 25 Août 2019
Keep a 100 x 99 (not 99 x 99) matrix of sticky locations. Initialize row 100 as true, the rest false. Now each iteration, there is no need to check whether the particle would pass y 99. Instead, each iteration check whether the location the particle would move to is marked as sticky; if it is, then end the current particle where it already is and mark that location as sticky.
This will not prevent a particle passing diagonally past a sticky block: if you have
CS
SP
where C is the current location, and P is the proposed location, and S are sticky locations (already occupied), then this logic would permit the passage of the particle, as the C->P transition would not involve any particle landing "on top of" another one.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Gravitation, Cosmology & Astrophysics dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by