群智能优化算法-测试函数matlab源码

Posted Tsingke

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了群智能优化算法-测试函数matlab源码相关的知识,希望对你有一定的参考价值。

群智能优化算法测试函数matlab源代码

global M;
creatematrix(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画ackley图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ackley x from[-5 5]
% x=-5:0.01:5;
% [x,y]=meshgrid(x);
% temp1=x.^2+y.^2;
% temp2=cos(2*pi*x)+cos(2*pi*y);
% z=20+exp(1)-20*exp(-0.2*sqrt(temp1/2))-exp(temp2/2);
% axis([-5,5,-5,5]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的ackley图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Rotated ackley x from[-5 5
% x=-5:0.01:5;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% temp1=x.^2+y.^2;
% temp2=cos(2*pi*x)+cos(2*pi*y);
% z=20+exp(1)-20*exp(-0.2*sqrt(temp1/2))-exp(temp2/2);
% axis([-5,5,-5,5]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画cigar图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%cigar
x=-5:0.01:5;
[x,y]=meshgrid(x);
z=x.^2+(10^4)*y.^2;
axis([-5,5,-5,5]);
meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的cigar图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rotated cigar x from [-5 5] 
% x=-7:0.01:7;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% z=x.^2+(10^4)*y.^2;
% axis([-7,7,-7,7]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画ellipse图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ellipse x from [-5 -5] 
% x=-5:0.01:5;
% [x,y]=meshgrid(x);
% z=x.^2+10.^4*(y.^2);
% axis([-5,5,-5,5]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画griewangk图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%griewangk 
% x=-600:1:600;
% [x,y]=meshgrid(x);
% temp1=(x.^2+y.^2)/4000;
% temp2=cos(x)*cos(y/sqrt(2));
% z=temp1-temp2+1;
% axis([-600,600,-600,600]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的griewangk图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Rotated griewangk
% x=-600:1:600;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% temp1=(x.^2+y.^2)/4000;
% temp2=cos(x)*cos(y/sqrt(2));
% z=temp1-temp2+1;
% axis([-600,600,-600,600]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画nocon_rastrigin图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%nocon_rastrigin
% x=-10:0.05:10;
% [x,y]=meshgrid(x);
% temp1=0;
% temp2=0;
% z=0;
% if abs(x)<1/2
% temp1=x;
% else
% temp1=round(2.*x)/2;
% end
% if abs(y)<1/2
% temp2=y;
% else
% temp2=round(2.*y)/2;
% end
% z=z+temp1.^2-10*cos(2*pi.*temp1)+temp2.^2-10*cos(2*pi.*temp2)+20;
% axis([-10,10,-10,10]);
% meshc(x,y,z);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的nocon_rastrigin图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Rotated nocon_rastrigin
% x=-15:0.05:15;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% temp1=0;
% temp2=0;
% z=0;
% if abs(x)<1/2
% temp1=x;
% else
% temp1=round(2.*x)/2;
% end
% if abs(y)<1/2
% temp2=y;
% else
% temp2=round(2.*y)/2;
% end
% z=z+temp1.^2-10*cos(2*pi.*temp1)+temp2.^2-10*cos(2*pi.*temp2)+20;
% axis([-15,15,-15,15]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画rastrigin图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rastrigin
% x=-10:0.05:10;
% [x,y]=meshgrid(x);
% temp1=x.^2-10*cos(2*pi.*x);
% temp2=y.^2-10*cos(2*pi.*y);
% z=temp1+temp2+20;
% axis([-10,10,-10,10]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的rastrigin图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Rotated rastrigin
% x=-15:0.05:15;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% temp1=x.^2-10*cos(2*pi.*x);
% temp2=y.^2-10*cos(2*pi.*y);
% z=temp1+temp2+20;
% axis([-15,15,-15,15]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画rosenbrock图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rosenbrock 
% x=-10:0.05:10;
% [x,y]=meshgrid(x);
% z=100*(y-x.^2).^2+(x-1).^2;
% axis([-10,10,-10,10]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画schwefel图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%schwefel
% x=-10:0.05:10;
% [x,y]=meshgrid(x);
% z=(x-x.^2).^2+(x-1).^2+(x-y.^2).^2+(y-1).^2;
% axis([-10,10,-10,10]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的schwefel图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Rotated schwefel
% x=-15:0.05:15;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% z=(x-x.^2).^2+(x-1).^2+(x-y.^2).^2+(y-1).^2;
% axis([-15,15,-15,15]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画sphere图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%sphere 
% x=-10:0.05:10;
% [x,y]=meshgrid(x);
% z=x.^2+y.^2;
% axis([-10,10,-10,10]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画sumcan图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%sumcan
% x=-0.16:0.0005:0.16;
% [x,y]=meshgrid(x);
% z=1./(10.^(-5)+abs(x)+abs(x+y));
% z=log10(z);
% axis([-0.16,0.16,-0.16,0.16]);
% mesh(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画tablet图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%tablet 
% x=-10:0.05:10;
% [x,y]=meshgrid(x);
% z=10.^4*x.^2+y.^2;
% axis([-10,10,-10,10]);
% mesh(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画Weierstrass图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Weierstrass 
% x=-1:0.005:1;
% [x,y]=meshgrid(x);
% z=0;
% for k=0:20
% z=z+0.5^k*cos(2*pi*3^k*(x+0.5))+0.5^k*cos(2*pi*3^k*(y+0.5));
% end
% temp=0;
% for k=0:20
% temp=temp+0.5^k*cos(2*pi*3^k*0.5);
% end
% z=z-2*temp;
% axis([-1,1,-1,1]);
% meshc(x,y,z);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%画旋转的Weierstrass图。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Rotated Weierstrass 
% x=-1.5:0.005:1.5;
% [x,y]=meshgrid(x);
% for i=1:size(x,1)
% for j=1:size(y,1)
% p=[x(i,j),y(i,j)]‘;
% x(i,j)=M(1,:)*p;
% y(i,j)=M(2,:)*p;
% end
% end
% z=0;
% for k=0:20
% z=z+0.5^k*cos(2*pi*3^k*(x+0.5))+0.5^k*cos(2*pi*3^k*(y+0.5));
% end
% temp=0;
% for k=0:20
% temp=temp+0.5^k*cos(2*pi*3^k*0.5);
% end
% z=z-2*temp;
% axis([-1.5,1.5,-1.5,1.5]);
% meshc(x,y,z);
% 
xlabel(‘x‘);
ylabel(‘y‘);
zlabel(‘f(x,y)‘);
colormap jet;
% clear;
%saveas(gcf,‘temp.jpg‘)

  

以上是关于群智能优化算法-测试函数matlab源码的主要内容,如果未能解决你的问题,请参考以下文章

优化算法天牛须搜索优化粒子群算法含Matlab源码 1256期

matlab-粒子群源码优化模糊隶属度函数值

优化预测基于matlab天牛须算法优化BP神经网络预测含Matlab源码 1318期

优化预测基于matlab天牛须算法优化BP神经网络预测含Matlab源码 1316期

优化预测基于matlab天牛须算法优化ELMAN神经网络预测含Matlab源码 1375期

优化预测基于matlab天牛须算法优化ELMAN神经网络预测含Matlab源码 1375期