# Untitled

unknown
plain_text
a month ago
5.4 kB
2
Indexable
Never
```function z=Sphere(x, y, d)
switch y

%Sphere
case 1
z=sum(x.^2);

%Schwefel 2.22
case 2
z=sum(abs(x))+prod(abs(x));

%Schwefel 1.2
case 3
z=0;
for i=1:d
z=z+sum(x(1:i))^2;
end

%Schwefel 2.21
case 4
z=max(abs(x));

%Rosenbrock
case 5
z=sum(100*(x(2:d)-(x(1:d-1).^2)).^2+(x(1:d-1)-1).^2);

%Step
case 6
z=sum(floor((x+.5)).^2);

%Quartic
case 7
z=sum([1:d].*(x.^4))+rand;

%%%%%%%%%%%%%%%%%%%%%%%%%%multimodal function%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Schwefel
case 8
z=sum(-x.*sin(sqrt(abs(x))));

%Rastrigin
case 9
z=sum(x.^2-10*cos(2*pi.*x))+10*d;

%Ackley
case 10
z=-20*exp(-.2*sqrt(sum(x.^2)/d))-exp(sum(cos(2*pi.*x))/d)+20+exp(1);

%Griewank
case 11
z=sum(x.^2)/4000-prod(cos(x./sqrt([1:d])))+1;

%Penalized
case 12
a=10;k=100;m=4;
d=length(x);
z=(pi/d)*(10*((sin(pi*(1+(x(1)+1)/4)))^2)+sum((((x(1:d-1)+1)./4).^2).*...
(1+10.*((sin(pi.*(1+(x(2:d)+1)./4)))).^2))+((x(d)+1)/4)^2)+sum(k.*...
((x-a).^m).*(x>a)+k.*((-x-a).^m).*(x<(-a)));

%Penalized2
case 13
a=10;k=100;m=4;
d=length(x);
z=.1*((sin(3*pi*x(1)))^2+sum((x(1:d-1)-1).^2.*(1+(sin(3.*pi.*x(2:d))).^2))+...
((x(d)-1)^2)*(1+(sin(2*pi*x(d)))^2))+sum(k.*...
((x-a).^m).*(x>a)+k.*((-x-a).^m).*(x<(-a)));

%%%%%%%%%%%%%%%%%%%%%%%%%%fixed-densionalmultimodalfunction%%%%%%%%%%%%%%

%Foxholes
case 14
a=[-32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32;,...
-32 -32 -32 -32 -32 -16 -16 -16 -16 -16 0 0 0 0 0 16 16 16 16 16 32 32 32 32 32];
for j=1:25
b(j)=sum((x'-a(:,j)).^6);
end
z=(1/500+sum(1./([1:25]+b))).^(-1);

%Kowalik
case 15
a=[.1957 .1947 .1735 .16 .0844 .0627 .0456 .0342 .0323 .0235 .0246];
b=[.25 .5 1 2 4 6 8 10 12 14 16];b=1./b;
z=sum((a-((x(1).*(b.^2+x(2).*b))./(b.^2+x(3).*b+x(4)))).^2);

%Six Hump Camel
case 16
z=4*(x(1)^2)-2.1*(x(1)^4)+(x(1)^6)/3+x(1)*x(2)-4*(x(2)^2)+4*(x(2)^4);

%Branin
case 17
z=(x(2)-(x(1)^2)*5.1/(4*(pi^2))+5/pi*x(1)-6)^2+10*(1-1/(8*pi))*cos(x(1))+10;

%GoldStein-Price
case 18
z=(1+(x(1)+x(2)+1)^2*(19-14*x(1)+3*(x(1)^2)-14*x(2)+6*x(1)*x(2)+3*x(2)^2))*...
(30+(2*x(1)-3*x(2))^2*(18-32*x(1)+12*(x(1)^2)+48*x(2)-36*x(1)*x(2)+27*(x(2)^2)));

%Hartman 3
case 19
a=[3 10 30;.1 10 35;3 10 30;.1 10 35];c=[1 1.2 3 3.2];
p=[.3689 .117 .2673;.4699 .4387 .747;.1091 .8732 .5547;.03815 .5743 .8828];
z=0;
for i=1:4
z=z-c(i)*exp(-(sum(a(i,:).*((x-p(i,:)).^2))));
end

%Hartman 6
case 20
af=[10 3 17 3.5 1.7 8;.05 10 17 .1 8 14;3 3.5 1.7 10 17 8;17 8 .05 10 .1 14];
cf=[1 1.2 3 3.2];
pf=[.1312 .1696 .5569 .0124 .8283 .5886;.2329 .4135 .8307 .3736 .1004 .9991;...
.2348 .1415 .3522 .2883 .3047 .6650;.4047 .8828 .8732 .5743 .1091 .0381];
z=0;
for i=1:4
z=z-cf(i)*exp(-(sum(af(i,:).*((x-pf(i,:)).^2))));
end

%Shekel 5
case 21
a=[4 4 4 4;1 1 1 1;8 8 8 8;6 6 6 6;3 7 3 7;2 9 2 9;5 5 3 3;8 1 8 1;6 2 6 2;7 3.6 7 3.6];
c=[0.1 0.2 0.2 0.4 0.4 0.6 0.3 0.7 0.5 0.5];
z=0;
for i=1:5
z=z-1/((x-a(i,:))*(x-a(i,:))'+c(i));
end

%Shekel 7
case 22
a=[4 4 4 4;1 1 1 1;8 8 8 8;6 6 6 6;3 7 3 7;2 9 2 9;5 5 3 3;8 1 8 1;6 2 6 2;7 3.6 7 3.6];
c=[0.1 0.2 0.2 0.4 0.4 0.6 0.3 0.7 0.5 0.5];
z=0;
for i=1:7
z=z-1/((x-a(i,:))*(x-a(i,:))'+c(i));
end

%Shekel 10
otherwise
a=[4 4 4 4;1 1 1 1;8 8 8 8;6 6 6 6;3 7 3 7;2 9 2 9;5 5 3 3;8 1 8 1;6 2 6 2;7 3.6 7 3.6];
c=[0.1 0.2 0.2 0.4 0.4 0.6 0.3 0.7 0.5 0.5];
z=0;
for i=1:10
z=z-1/((x-a(i,:))*(x-a(i,:))'+c(i));
end
end
```