function [alfa,alfa_val] = Grey_Wolf_Optimizer (Func_name,N,Lower,Upper,Maxiter)

 
fobj = TestFunctions (Func_name); 
D=length(Lower);
X=zeros(N,D);
a=zeros(1,D);
alfa=zeros(1,D);
beta=zeros(1,D);
delta=zeros(1,D);
A1=zeros(1,D);
C1=zeros(1,D);
A2=zeros(1,D);
C2=zeros(1,D);
A3=zeros(1,D);
C3=zeros(1,D);
X1=zeros(N,D);
X2=zeros(N,D);
X3=zeros(N,D);

 

for i=1:N
  for j=1:D
    X(i,j)=Lower(j)+(Upper(j)-Lower(j))*rand;
  endfor
endfor
X = sortX (X,fobj,N,D);
alfa=X(1,:);
beta=X(2,:);
delta=X(3,:);

iter=1;

while(iter <= Maxiter)
     a(1:D)=2.0-(iter*(2.0/Maxiter));
     for i=1:N
        A1=2.0.*a.*rand-a;
        C1=2.0.*rand;
        X1(i,:)=alfa-A1.*(abs(C1.*alfa-X(i,:)));
        X1 = boundary (X1, Lower,Upper,N,D);
        
        A2=2.0.*a.*rand-a;
        C2=2.0.*rand;
        X2(i,:)=beta-A2.*(abs(C2.*beta-X(i,:)));
        X2 = boundary (X2, Lower,Upper,N,D);
        
        A3=2.0.*a.*rand-a;
        C3=2.0.*rand;
        X3(i,:)=delta-A3.*(abs(C3.*delta-X(i,:)));
        X3 = boundary (X3, Lower,Upper,N,D);
        
        X(i,:)=(X1(i,:)+X2(i,:)+X3(i,:))./3.0;
     endfor
     
     X = boundary (X, Lower,Upper,N,D);
     X = sortX (X,fobj,N,D);
     alfa=X(1,:);
     beta=X(2,:);
     delta=X(3,:);
     alfa_val=fobj(alfa);
     iter=iter+1;
end
  
 



endfunction
