function [f,X] = DE
clc;
clear all;
close all;
% f - optimal fitness
% X - optimal solution
% CONTROL PARAMETERS %
D =16; % dimension of problem
NP = 60; % size of population
F = 0.5; % differentiation constant
CR = 0.8; % crossover constant
GEN = 1000; % number of generations
fre=3e9;
lamda=(3e8)/fre;
L = 0.5; % low boundary constraint
H = 1;% high boundary constraint
% *************************** %
% ** ALGORITHM��S VARIABLES ** %
% *************************** %
X = zeros(D,1); % trial vector
Pop = zeros(D,NP); % population
Fit = zeros(1,NP); % fitness
iBest = 1; % index of the best solution
r = zeros(3,1); % randomly selected indices
% *********************** %
% ** CREATE POPULATION ** %
% *********************** %
% initialize random number generator
% rand('state',sum(100*clock));
for j = 1:NP % initialize each individual
Pop(:,j) = L + (H-L)*rand(D,1); % within b.constraints
Fit(j) = fnc(Pop(:,j)); % and evaluate fitness
end
% ****************** %
% ** OPTIMIZATION ** %
% ****************** %
for g = 1:GEN % for each generation
for j = 1:NP % for each individual
% choose three random individuals from population,
% mutually different and different from j
r(1) = floor(rand()* NP) + 1;
while r(1)==j
r(1) = floor(rand()* NP) + 1;
end
r(2) = floor(rand()* NP) + 1;
while (r(2)==r(1))||(r(2)==j)
r(2) = floor(rand()* NP) + 1;
end
r(3) = floor(rand()* NP) + 1;
while (r(3)==r(2))||(r(3)==r(1))||(r(3)==j)
r(3) = floor(rand()* NP) + 1;
end
% create trial individual
% in which at least one parameter is changed
Rnd = floor(rand()*10) + 1;
for i = 1:D
if ( rand()<CR ) || ( Rnd==i )
X(i) = Pop(i,r(3)) +F*(Pop(i,r(1)) - Pop(i,r(2)));
else
X(i) = Pop(i,j);
end
end
% verify boundary constraints
for i = 1:D
if (X(i)<L)||(X(i)>H)
X(i) = L+ (H-L)*rand();
end
end
% select the best individual
% between trial and current ones
% calculate fitness of trial individual
f = fnc(X);
% if trial is better or equal than current
if f <= Fit(j)
Pop(:,j) = X; % replace current by trial
Fit(j) = f ;
% if trial is better than the best
if f <= Fit(iBest)
iBest = j ; % update the best��s index
end
end
end
end
% ************* %
% ** RESULTS ** %
% ************* %
f = Fit(iBest)
X = Pop(:,iBest)
k=2*pi/lamda;
t=1:0.5:179;
d=0;
z1=1;
z2=0;
msll=-100;
for ii=1:16
d=X(ii)*lamda+d;
z1=z1+exp((-1)^(-1/2)*(k*d*cos(t/180*pi)));
end
kk=1;
for jj=17:31
d=X(jj-kk*2)*lamda+d;
z2=z2+exp((-1)^(-1/2)*(k*d*cos(t/180*pi)));
kk=kk+1;
end
z=z1+z2;
maxz=abs(max(z));
z=abs(z);
f2=20*log10(z./maxz);
plot(t,f2);
for i=[1:1:173,185:1:357];
if f2(i)>msll
msll=f2(i);
end
end
PSLL=msll
% ============================================== %
function f = fnc(X)
% fitness function
fre=3e9;
lamda=(3e8)/fre;
k=2*pi/lamda;
t=1:0.5:179;
msll=-100;
slvl=-23;
d=0;
z1=1;
z2=0;
for ii=1:16
d=X(ii)*lamda+d;
z1=z1+exp(j*(k*d*cos(t/180*pi)));
end
kk=1;
for jj=17:31
d=X(jj-kk*2)*lamda+d;
z2=z2+exp(j*(k*d*cos(t/180*pi)));
kk=kk+1;
end
z=z1+z2;
maxz=abs(max(z));
z=abs(z);
f1=20*log10(z./maxz);
for i=[1:1:173,185:1:357];
if f1(i)>msll
msll=f1(i);
end
end
f=abs(msll-slvl);