Simulating Levy walk in MATLAB. (Not Levy Flight)
I am trying to simulate Levy Walk in 2D (Not Levy Flight). I do get the MSD and VCAF correctly, but I don’t get the step length distribution correctly ( Levy Walk step lengths have heavy tails). I don’t know my simulation is entirely correct. Can someone confirm my code ?
alpha=1.4;
x(1)=0;
y(1)=0;
n = 100; %
dt =0.1; % time step
v=1; % velocity
for i=1:n
t= round(abs((rand()).^(-1/alpha))./dt); % time before the change in direction taken from a simple stable distribution
theta = 2*pi*rand;
time(i)=t;
for j=1:t
x(end+1) = x(end) + v*dt*cos(theta);
y(end+1) = y(end) + v*dt*sin(theta);
end
end
figure(1);
plot(x, y, ‘-‘);
%% Distribution of step size
dx = diff(x);
dy = diff(y);
vxy=([dx, dy]);
bins = linspace(min(vxy), max(vxy), 75);
[count, edge]= histcounts(vxy, bins, ‘Normalization’, ‘PDF’);
pd= fitdist(transpose(vxy),’Normal’);
countfit=pdf(pd, edge(1:end-1));
figure(3)
semilogy(edge(1:end-1), count, ‘o’, ‘LineWidth’,2.0); hold on;
semilogy(edge(1:end-1),countfit,’-r’,’LineWidth’,2.0); hold off;I am trying to simulate Levy Walk in 2D (Not Levy Flight). I do get the MSD and VCAF correctly, but I don’t get the step length distribution correctly ( Levy Walk step lengths have heavy tails). I don’t know my simulation is entirely correct. Can someone confirm my code ?
alpha=1.4;
x(1)=0;
y(1)=0;
n = 100; %
dt =0.1; % time step
v=1; % velocity
for i=1:n
t= round(abs((rand()).^(-1/alpha))./dt); % time before the change in direction taken from a simple stable distribution
theta = 2*pi*rand;
time(i)=t;
for j=1:t
x(end+1) = x(end) + v*dt*cos(theta);
y(end+1) = y(end) + v*dt*sin(theta);
end
end
figure(1);
plot(x, y, ‘-‘);
%% Distribution of step size
dx = diff(x);
dy = diff(y);
vxy=([dx, dy]);
bins = linspace(min(vxy), max(vxy), 75);
[count, edge]= histcounts(vxy, bins, ‘Normalization’, ‘PDF’);
pd= fitdist(transpose(vxy),’Normal’);
countfit=pdf(pd, edge(1:end-1));
figure(3)
semilogy(edge(1:end-1), count, ‘o’, ‘LineWidth’,2.0); hold on;
semilogy(edge(1:end-1),countfit,’-r’,’LineWidth’,2.0); hold off; I am trying to simulate Levy Walk in 2D (Not Levy Flight). I do get the MSD and VCAF correctly, but I don’t get the step length distribution correctly ( Levy Walk step lengths have heavy tails). I don’t know my simulation is entirely correct. Can someone confirm my code ?
alpha=1.4;
x(1)=0;
y(1)=0;
n = 100; %
dt =0.1; % time step
v=1; % velocity
for i=1:n
t= round(abs((rand()).^(-1/alpha))./dt); % time before the change in direction taken from a simple stable distribution
theta = 2*pi*rand;
time(i)=t;
for j=1:t
x(end+1) = x(end) + v*dt*cos(theta);
y(end+1) = y(end) + v*dt*sin(theta);
end
end
figure(1);
plot(x, y, ‘-‘);
%% Distribution of step size
dx = diff(x);
dy = diff(y);
vxy=([dx, dy]);
bins = linspace(min(vxy), max(vxy), 75);
[count, edge]= histcounts(vxy, bins, ‘Normalization’, ‘PDF’);
pd= fitdist(transpose(vxy),’Normal’);
countfit=pdf(pd, edge(1:end-1));
figure(3)
semilogy(edge(1:end-1), count, ‘o’, ‘LineWidth’,2.0); hold on;
semilogy(edge(1:end-1),countfit,’-r’,’LineWidth’,2.0); hold off; randomwalk, biology, levywalk, physics MATLAB Answers — New Questions