% In the name of God
% optimaztion convex
% tamrin 2
% infeasible newton
clear all
clc
load ( 'opti' ,'p','q')
load ( 'equal', 'A', 'b')

a=0.2; %alpha
B=0.6;
dx=1+zeros(20,1);
dg=1+zeros(20,1);
Xp=inv(A)*b;
x=Xp+(1.1+dx);
g=(-1)*inv(A)*((2)*(p*x+q));
dx=inv(A)*(-A*x+b);
dg=(-1)*inv(A)*(p*x+q+A*g+2*p*dx);
x1=(-2)*(p*x+q)-A*g;
g1=-(A*x+b);
r=[x1;g1];
while( norm(r,2)>10)
   t=1;
   x2=(-2)*(p*(x+t*dx)+q)-A*(g+t*dg);
   g2=-(A*(x+t*dx)+b);
   r1=[x2;g2];
   while ( norm(r1,2)>(1-a*t)*norm(r,2))
     t=B*t;
     x2=(-2)*(p*(x+t*dx)+q)-A*(g+t*dg);
     g2=-(A*(x+t*dx)+b);
     r1=[x2;g2];
   end
   dx=inv(A)*(-A*x+b);
   dg=(-1)*inv(A)*(p*x+q+A*g+2*p*dx);
   x1=(-2)*(p*(x+dx)+q)-A*(g+dg);
   g1=-(A*(x+dx)+b);
   r=[x1;g1];
   x=x+t*dx;
   g=g+t*dg;
end
