% Data Envelope Analysis
% Written by Byungmock Jeon, 2001

function [DEA]=dea(y,x,n)

options=optimset('Display','off');
[nt,k]=size(x); 
t=nt/n;
   
DEA=[];

  for i=1:t 

     ind=i:t:nt;
     yt=y(ind) ; 
     xt=x(ind,:) ;   

      dt0 = [];

   for j=1:n

     yj=yt(j);
     xj=xt(j,:); 

     f=[-1 ; zeros(n,1)];

     a11=[1 -1*yt'./yj]; 
     c11=[-1]; 

     for p=1:k
      a11=[a11;0 xt(:,p)'];
      c11=[c11;xj(p)];
     end;

     Aeq=[]; beq=[];
     vlb=[-1; zeros(n,1)];
     vub=[];

     % d_bar=linprog(f,a11,c11,a11(1,:),c11(1),vlb,vub,zeros(n+1,1),options);  % with equality constraint

      d_bar=linprog(f,a11,c11,Aeq,beq,vlb,vub,zeros(n+1,1),options);

      dt0=[dt0 1/(1+d_bar(1)) ]  ;
     
   end;
DEA=[DEA;dt0];

end;
 
