# How to simulate Lévy flights?

I found this code:

function [z] = levy(n,m,beta)
% This function implements Levy's flight.

%'Multiobjective cuckoo search for design optimization Xin-She Yang, Suash Deb'.

% Coded by Hemanth Manjunatha on Nov 13 2015.

% Input parameters
% n     -> Number of steps
% m     -> Number of Dimensions
% beta  -> Power law index  % Note: 1 < beta < 2

% Output
% z     -> 'n' levy steps in 'm' dimension

num = gamma(1+beta)*sin(pi*beta/2); % used for Numerator

den = gamma((1+beta)/2)*beta*2^((beta-1)/2); % used for Denominator

sigma_u = (num/den)^(1/beta);% Standard deviation

u = random('Normal',0,sigma_u^2,n,m);

v = random('Normal',0,1,n,m);

z = u./(abs(v).^(1/beta));

end


The code above simulates Lévy flight, but I don't really understand why it really works or why it simulates Lévy flight? I mean, I don't see how the distribution bellow emerges from the algorithm above:

$$Pr(U>u) = \begin{cases} 1 &:\ u < 1,\\ u^{-D} &:\ u \ge 1. \end{cases}$$

If I run plot(levy(1000,1,1.5)) this is what I get:

Also the cumsum doesn't look like a Levy Flight:

• Are you looking for an explanation what a Levy Flight is? – usεr11852 Feb 25 '18 at 0:27
• @usεr11852 maybe an explanation how this code is related to any definition of Lévy flight. – 0x90 Feb 25 '18 at 1:02
• Did you look at the paper referenced in the code? – Mark L. Stone Feb 25 '18 at 2:04