cec2014函数代码matlab
时间: 2023-08-15 10:04:29 浏览: 258
由于您没有明确指出cec2014函数中的哪个具体函数,我假设您是指CEC2014年度国际智能计算竞赛中的测试函数集。以下是CEC2014年度竞赛的测试函数的Matlab代码:
1. Sphere Function
```
function f = sphere(x)
f=sum(x.^2);
end
```
2. Rotated High Conditioned Elliptic Function
```
function f=elliptic(x)
D=length(x);
f=0;
for i=1:D
f=f+10^6^(i/D-1)*x(i)^2;
end
end
```
3. Rotated Bent Cigar Function
```
function f=bent_cigar(x)
D=length(x);
f=x(1)^2+10^6*sum(x(2:D).^2);
end
```
4. Rotated Discus Function
```
function f=discus(x)
D=length(x);
f=10^6*x(1)^2+sum(x(2:D).^2);
end
```
5. Different Powers Function
```
function f=different_powers(x)
D=length(x);
f=sum(abs(x).^(2+4*(1:D-1)/(D-1)));
end
```
6. Rotated Rosenbrock's Function
```
function f=rosenbrock(x)
D=length(x);
f=sum(100*(x(2:D)-x(1:D-1).^2).^2+(1-x(1:D-1)).^2);
end
```
7. Rotated Schaffers F7 Function
```
function f=schaffers_F7(x)
D=length(x);
sum1=0;
for i=1:D-1
xi=x(i);
xj=x(i+1);
new=x1^2+x2^2;
old=sin(sqrt(old));
sum1=sum1+old;
end
f=sum1+(sin(sqrt(x(D)^2+x(1)^2)))^2-0.5;
end
```
8. Rotated Ackley's Function
```
function f=ackley(x)
D=length(x);
sum1=0;
sum2=0;
for i=1:D
sum1=sum1+x(i)^2;
sum2=sum2+cos(2*pi*x(i));
end
f=-20*exp(-0.2*sqrt(sum1/D))-exp(sum2/D)+20+exp(1);
end
```
9. Rotated Weierstrass Function
```
function f=weierstrass(x)
D=length(x);
a=0.5;
b=3;
kmax=20;
c=2*pi;
sum1=0;
for i=1:D
sum2=0;
for k=0:kmax
sum2=sum2+a^k*cos(c^k*(x(i)+0.5));
end
sum1=sum1+sum2;
end
sum3=0;
for k=0:kmax
sum3=sum3+a^k*cos(c^k*0.5);
end
f=sum1-D*sum3;
end
```
10. Rotated Griewank's Function
```
function f=griewank(x)
D=length(x);
sum1=0;
prod1=1;
for i=1:D
sum1=sum1+x(i)^2/4000;
prod1=prod1*cos(x(i)/sqrt(i));
end
f=sum1-prod1+1;
end
```
希望这些函数的代码可以帮到您。
阅读全文