function [out1, out2, out3] = nashvectorfield(t,x,flag)
%
%
global A W
a=A(1,1);
b=A(1,2);
c=A(2,1);
d=A(2,2);
x1=x(1);
y1=x(2);
%phi11=W(1,1)*max(0*x1,(1-x1)*((c-a)*y1+(d-b)*(1-y1)));
%phi12=W(1,2)*max(0*x1,-x1*((c-a)*y1+(d-b)*(1-y1)));
%phi21=W(2,1)*max(0*y1,(1-y1)*((a-b)*x1+(c-d)*(1-x1)));
%phi22=W(2,2)*max(0*y1,-y1*((a-b)*x1+(c-d)*(1-x1)));

phi11=W(1,1)*(x1-1)*((c-a)*y1+(d-b)*(1-y1))*((x1-1)*((c-a)*y1+(d-b)*(1-y1))>0);
phi12=W(1,2)*(x1*((c-a)*y1+(d-b)*(1-y1)))*(x1*((c-a)*y1+(d-b)*(1-y1))>0);
phi21=W(2,1)*(y1-1)*((a-b)*x1+(c-d)*(1-x1))*((y1-1)*((a-b)*x1+(c-d)*(1-x1))>0);
phi22=W(2,2)*(y1*((a-b)*x1+(c-d)*(1-x1)))*(y1*((a-b)*x1+(c-d)*(1-x1))>0);

if nargin < 3 | isempty(flag)
   out1=[phi11-x1*(phi11+phi12);
    phi21-y1*(phi21+phi22)];

else
   switch(flag)
   case 'init'
     out1 = [0; 50];
     out2 = [-0.2507,  -0.1418];
     out3 = []; %odeset('Vectorized', 1);
     case 'events' 
     sec1 = x1;   
     sec2 = x1;
     sec3 = x1; 
     out1 = [sec1,sec2,sec3];
     out2 = [0,0,1];
     out3 = [1,-1,-1];
   otherwise
      error(['Unknown flag ''' flag ''.']);
   end
end; 


