%Federica Tinti (ftinti@dm.unipd.it)
%Department of Mathematics of Ferrara (ITALY)
%
%Extragradient method with constant steplength 
%
clear all
%
stringa=input('test problem=', 's');
eval(stringa);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%parameters 
P=eye(n);
eps=1e-4;
rxx=0;
np=0;			
%
fx=feval(fs,x);
nf=1;
iteresterna=0;
alpha=input('alpha=');
while  iteresterna==0 | norm(rxx)>eps 
   iteresterna=iteresterna+1;
   f=-(x-alpha*fx);
   options=optimset('LargeScale','off');
   [xx]=quadprog(P,f,A,b,Aeq,beq,lb,ub,x,options);
   xx=abs(xx);
   np=np+1;
   fxx=feval(fs,xx);
   nf=nf+1;
   f=-x+alpha*fxx;
    options=optimset('LargeScale','off');
    [xnew]=quadprog(P,f,A,b,Aeq,beq,lb,ub,x,options);
    xnew=abs(xnew);
    np=np+1;
    rxx=xnew-x;
    x=xnew;
    fx=feval(fs,x);
    nf=nf+1;
    fprintf('norm(rxx)=%g, \n',norm(rxx));%pause
 end;
 fprintf('iteresterna=%g, np=%g, nf=%g \n',iteresterna,np,nf);
 f=-(x-feval(fs,x));
 options=optimset('LargeScale','off');
 [xnew]=quadprog(P,f,A,b,Aeq,beq,lb,ub,x,options);
 xnew=abs(xnew);
 rx=x-xnew

            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            