function [dX,dy,dZ]=slvkkt(mu,A,TA,b,L,X,y,Z)
% Solve the KKT conditions for the step direction

% case 1:
%  Use an SOR type iteration for the solution of the augmented
%  system.
%  Call:  [dX,dy,dZ]=slvkkt(mu,A,b,L,X,y,Z)

m=length(b);n=size(X,2);n2=size(A,2);tn=size(TA,2);
T=[  
    [speye(m)  zeros(m)
     zeros(m) -speye(m) ]    [ -TA  zeros(m,tn); zeros(m,tn)  TA]
  zeros(2*tn,2*m+2*tn)
];
'inside slvkkt'
keyboard
x=reshape(X,n2,1);
z=reshape(Z,n2,1);
Fd=Z+L-reshape(A'*y,n,n);
Fp=b-A*x;      %  rhs 1
AFd=A*reshape(Fd,n2,1); % rhs 2
Z2=Z^2;X2=X^2;
ZX=Z*X;
XZ=ZX';
ZZX=Z*ZX;
XZZ=ZZX';
XXZ=X*XZ;
ZXX=XXZ';
ZZF=(ZZX+XZZ)/2-mu*Z;   % rhs 3
FXZF=Fd+(ZXX+XXZ)/2-mu*X;   % rhs 4

% initial estimates 
dv=-Fp;
dy=AFd;
dX=ZZF;
dZ=-FXZF;
dx=reshape(dX,n2,1);
dz=reshape(dZ,n2,1);
for i=1:20,
   dvn=A*dx-Fp;
   dyn=A*dz+AFd;
   Z2dX=Z2*dX;
   X2dZ=X2*dZ;
   ZXdZ=ZX*dZ;
   ZXdX=ZX*dX;
   dXn=reshape(A'*dv,n,n) +  (Z2dX+Z2dX')/2+dX + (ZXdZ+ZXdZ')/2 +ZZF;
   dZn=reshape(A'*dy,n,n) -  (ZXdX+ZXdX')/2 -(X2dZ+X2dZ')/2 -FXZF;
   'error in iteration'
   error=norm(dXn-dX)+norm(dZn-dZ)+norm(dvn-dv)+norm(dyn-dy)
   keyboard
   pause
   dX=dXn;dZ=dZn;
   dx=reshape(dX,n2,1); dz=reshape(dZ,n2,1);
   dv=dvn;dy=dyn;
end
