mercredi 24 mai 2017

Simulating hard random walkers in matlab

I have written a code to simulate the motion of circular particles in a 2d box. Whenever they move out of the box, I put them inside the box and near the wall, they go outside from it. I want to add the diameter of particles in the code, which means when the distance between the center of two circles become less than 2R, they separate along the line connecting their centers. Could anyone suggest a code to prevent overlap of particles?

This is my code which overlap is not considered in:

     clear all
close all
l = 224; nn = 800; %number of particles
time = 1000; dd = 1;
x= l*rand(1,nn);
y= l*rand(1,nn);

for t = 1:time;
x= x + rand(1,nn);
y=y+rand(1,nn);
index = (x < 0); x(index) = abs(normrnd(0,1,1,nnz(index)));
index = (y < 0); y(index) = abs(normrnd(0,1,1,nnz(index)));
index = (x > l); x(index) = l-abs(normrnd(0,1,1,nnz(index)));
index = (y > l); y(index) = l-abs(normrnd(0,1,1,nnz(index)));
end




Aucun commentaire:

Enregistrer un commentaire