I want to model the Brownian motion with multiple molecules/particles and animate them. So far I have come up with this code solution but I am unable to get the desired result. Below is my code
N = 500; % number of samples
tau = .1; % time interval in seconds
D = 10; % diffusion coefficient
NumMolecules = 500; % number of moelcues to be released
k = sqrt(2*D*tau); % scaling factor
dx = k * randn(N,NumMolecules);
dy = k * randn(N,NumMolecules);
x = cumsum(dx);
y = cumsum(dy);
h = gscatter(x(1,:),y(1,:),1:NumMolecules,'b');
for k = 2:N
for p = 1:NumMolecules
h(p).XData = x(k,p);
h(p).YData = x(k,p);
end
drawnow limitrate
end
drawnow
Can anyone tell me why I am unable to get the desired results?
Edit
Desired result: To animate the motion of the molecules using ‘drawnow’ function