function [BEST, BESTFIT] =Poor_and_Rich_Optimization (fobj,Lower,Upper,Maxiter)
 
fobj = TestFunctions (Func_name); 
D=length(Lower);
N=length(Lower);
X=zeros(N,D);
XNEW=zeros(N,D);
POOR=zeros(N/2,D); 
RICH=zeros(N/2,D);
NEWPOOR=zeros(N/2,D);
NEWRICH=zeros(N/2,D);
BESTPOOR=zeros(1,D);
BESTRICH=zeros(1,D);
WORSTRICH=zeros(1,D);
BEST=zeros(1,D);
RICHMEAN=zeros(1,D);
PATTERN=zeros(1,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);
BEST=X(1,:);

iter=1;

while(iter <= Maxiter)
  
    for i=1:N/2
      RICH(i,:)=X(i,:);
    endfor
    
    for i=(N/2)+1:N
      POOR(i-(N/2),:)=X(i,:);
    endfor
    
    BESTPOOR=POOR(1,:);
    
    for i=1:N/2
      NEWRICH(i,:)=RICH(i,:)+rand.*(RICH(i,:)-BESTPOOR);
    end
    
    NEWRICH = boundary (NEWRICH, Lower,Upper,N/2,D);
    
    if (rand<0.06)
      for i=1:N/2
        NEWRICH(i,:)=NEWRICH(i,:).*randn;
      end
    end
    
    NEWRICH = boundary (NEWRICH, Lower,Upper,N/2,D);
    
    RICHMEAN=mean(RICH);
    
    BESTRICH=RICH(1,:);
    WORSTRICH=RICH(N/2,:);
    PATTERN=(BESTRICH+RICHMEAN+WORSTRICH)./3.0;
    
    for i=1:N/2
      NEWPOOR(i,:)=POOR(i,:)+(rand.*PATTERN-POOR(i,:));
    end  
    
    NEWPOOR = boundary (NEWPOOR, Lower,Upper,N/2,D); 
    
    if (rand<0.06)
      for i=1:N/2
        NEWPOOR(i,:)=NEWPOOR(i,:).*randn;
      end
    end
    
    NEWPOOR = boundary (NEWPOOR, Lower,Upper,N/2,D); 
    
    for i=1:N/2
      XNEW(i,:)=NEWRICH(i,:);
    end
   
    for i=((N/2)+1):N 
      XNEW(i,:)=NEWPOOR(i-(N/2),:);
    end  
    
    X = update (X,XNEW,fobj);
    
    X=sortX (X,fobj,N,D);
    BEST=X(1,:);
    BESTFIT=fobj(X(i,:));
    iter=iter+1;
end

 



endfunction
