📄 mtpatest1.m
字号:
function [z] =MTPAtest1(x,n,Step)
% 1.sphere function 5.12>x>-5.12 0
if Step==1
z=0;
for i=1:n
z=z+(x(i))^2;
end
%2. Rosenbrock function 2.048>x>-2.048 x=-1 0
else
if Step==2
t=0;
for i=1:n-1
t=t+100*(x(i+1)-(x(i))^2)^2+(1-x(i))^2;
end
z=t;
%3. 3rd De Jong's function 5.12>x>-5.12 0
else
if Step==3
z=0;
for i=1:n
z=z+floor(x(i));
end
z=6*n+z;
% 4.MaxMod function 10>x>-10
else
if Step==4
z=0;
for i=1:n
z=i*(x(i))^4+z;
end
z=z+normrnd(0,1);
%5.Shekel function 65.536>x>-65.536
else
if Step==5
a=[-32,-16,0,16,32];
aa=repmat(a,1,5);
b=[-32*ones(1,5),-16*ones(1,5),zeros(1,5),16*ones(1,5),32*ones(1,5)];
A=[b;aa];
t=zeros(1,25);
for j=1:25
for i=1:2
t(j)=t(j)+(x(i)-A(i,j)).^6;
end
t(j)=1./(t(j)+j);
end
z=1/(1/500+sum(t));
%
%
% % 6.Rastrigin function -5.12<xi<5.12 0
else
if Step==6
t=0;
for i=1:n
t=t+x(i)^2-10*cos(2*pi*x(i));
end
z=t+n*10;
% >> TPA(100,200,0.3,50,50000,20,5.12)
%
%7.Schwefel function -500<xi<500
else
if Step==7
t=0;
for i=1:n
t=t+(-x(i)*sin(sqrt(abs(x(i)))));
end
z=418.98288727216249*n+t;
% % 8.Griewangke function -600<x600 0
else
if Step==8
t1=0;
t2=1;
for kk=1:n
t1=t1+(x(kk))^2;
t2=t2*cos(x(kk)/sqrt(kk));
end
z=t1/4000-t2+1;
% %9.Ackley function 32.768>x>-32.768 0
else
z=0;
if Step==9
%t1=0;
%t2=0;
for i=1:n-1
%t1=t1+(x(i))^2;
%t2=t2+cos(2*pi*x(i));
z=20+exp(1)-20*exp(-0.2*sqrt(0.5*x(i+1)^2+x(i)^2))-exp(0.5*(cos(2*pi*x(i+1))+cos(2*pi*x(i))));
end
%z=-20*exp(-0.2*sqrt(t1/n))-exp(t2/n)+20+exp(1);
% %10.Streched V sine function -10<x<10 0
else
if Step==10
z=0;
for i=1:n-1
% z1(i)=(x(i))^4+4*(x(i))^3+4*(x(i))^2;
%z2(i)=(x(i))^2;
z=z+(((x(i))^2+(x(i+1))^2)^0.25)*((sin((50*(x(i+1)^2+x(i)^2))^0.1))^2+1);
end
%z=z1(1)+z2(2);
% z=(x(1)^2+x(2)^2)^0.25*(sin((50*(x(2)^2+x(1)^2))^0.1)^2+1)+(x(2)^2+x(3)^2 )^0.25*(sin((50*(x(3)^2+x(2)^2))^0.1)^2+1);
else
if Step==11
z=0;
for i=1:n-1
z=z+((exp(1))^((1/8)*((x(i+1))^2+0.5*x(i)*x(i+1)+(x(i))^2)))*cos(4*sqrt((x(i+1))^2+0.5*x(i)*x(i+1)+(x(i))^2));
end
else
if Step==12
z=0;
for i=1:n
t(i+1)=x(i+1)+1;
a(i)=sqrt(abs(t(i+1)-x(i)));
b(i)=sqrt(abs(t(i+1)+x(i)));
z=z+t(i+1)*cos(a(i))*sin(b(i))+x(i)*cos(b(i))*sin(a(i));
end
else
if Step==13
z=0;
for i=n-1
x1=(sin(sqrt((x(i+1))^2+100*(x(i))^2)))^2-0.5;
y1=0.001*((x(i+1))^2-2*x(i+1)*x(i)+(x(i))^2)^2+1;
z=x1/y1 + 0.5;
end
else
if Step==14
z=0;
x1=0;
y1=0;
aa=20;
bb=0.2;
cc=2*pi;
for i=1:n
x1=x1+(x(i))^2;
y1=y1+cos(cc*x(i));
end
x2=x1./n;
y2=y1./n;
z=-aa*(exp(-bb*sqrt(x2))-exp(y2))+aa+exp(1);
else
if Step==15
%for i=1:n
% x(i)=fix(x(i));
%end
%z=max(x);
z=max([abs(x(1:n))]);
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -