How to form an aggregate from a random walk?

2 views (last 30 days)
Jack
Jack on 17 Dec 2017
Edited: Jack on 17 Dec 2017
I am making a random walk function that starts at a given boundary point and runs the a walk until the 'particle' attaches to a seed particle at (0,0,0). The process is repeated for N number of particles and an aggregate or cluster forms. The method is fairly obvious and the variable that stores the coordinates of the aggregate is agg. I want to be able to see this plotted in 3D but my method isn't working. Thanks for any help.
function [x,y,z,agg] = DLARandWalk(n,dt,b)
% Random Walk Function
s = round(randn(3,n-1));
% Direction is random.
dx = s(1,1:n-1);
dy = s(2,1:n-1);
dz = s(3,1:n-1);
x = zeros(1,n);
y = zeros(1,n);
z = zeros(1,n);
% Set intial position to Boundary
x(1) = -1*b;
y(1) = -1*b;
z(1) = -1*b;
%%Map Creation
%agg = zeros(b,b,b);
agg = zeros(3,n);
stuck = 0;
while stuck == 0
for a = 2:n-1
if abs(x(a-1)) <= b
x(a) = x(a-1) + dx(a);
else
x(a) = sign(x(a-1))*b;
end
if abs(y(a-1)) <= b
y(a) = y(a-1) + dy(a);
else
y(a) = sign(y(a-1))*b;
end
if abs(z(a-1)) <= b
z(a) = z(a-1) + dz(a);
else
z(a) = sign(z(a-1))*b;
end
if (x(a) == agg(1,a-1) + 1)||(x(a) == agg(1,a-1) - 1)
x(a:n) = x(a);
y(a:n) = y(a);
z(a:n) = z(a);
agg(1,a) = x(a);
agg(2,a) = y(a);
agg(3,a) = z(a);
stuck = 1;
end
if (y(a) == agg(2,a-1) + 1)||(y(a) == agg(2,a-1) - 1)
x(a:n) = x(a);
y(a:n) = y(a);
z(a:n) = z(a);
agg(1,a) = x(a);
agg(2,a) = y(a);
agg(3,a) = z(a);
stuck = 1;
end
if (z(a) == agg(3,a-1) + 1)||(z(a) == agg(3,a-1) - 1)
x(a:n) = x(a);
y(a:n) = y(a);
z(a:n) = z(a);
agg(1,a) = x(a);
agg(2,a) = y(a);
agg(3,a) = z(a);
stuck = 1;
end
end
end
x(n) = x(n-1);
y(n) = y(n-1);
z(n) = z(n-1);
return

Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!