之前研究布谷鸟算法,一直在找levy飞行轨迹代码实现,一直没找到就自己写了一个
x = [0,0]; y = [0,0]; beta = 3/2; alpha_u = ((gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2))))^(1/beta); alpha_v = 1; for i=1:1000 u = alpha_u*randn(1); v = alpha_v*randn(1); s = u/(abs(v))^(1/beta); x(:,1) = x(:,2); x(:,2) = x(:,1)+1*s; u = alpha_u*randn(1); v = alpha_v*randn(1); s = u/(abs(v))^(1/beta); y(:,1) = y(:,2); y(:,2) = y(:,1)+1*s; plot(x,y); hold on; end axis square;
迭代1000次运行结果: