MATLAB: I am trying to simulate Brownian motion where the initial position of the particles are generated by random number generators. I need to freeze the particles when it reaches a particular position, how can i do it? kindly help

brownian motionparticles

I am trying to simulate Brownian motion where the initial position of the particles are generated by random number generators. I need to freeze the particles when it reaches a particular position, how can i do it? kindly help

Best Answer

How not? Just stop updating those particles once you have detected they have reached the position.
You might want to do something like create a logical vector StillActive, initialized to all true. When the particle is in position, mark it false. Only do calculations on entries that are still true.
Positions(StillActive) = Positions(StillActive) + randn(sum(StillActive),1);
Related Question