function [x,f,i] = sd_ros()

% tol: stopping criterion on the norm of gradient at current x default at '1e-3'.
tol = 2e-4;

% maxit: maximum number of iterations
maxit=20000;

% x0: initial guess for the SD method:
% x0=[1.2;1.2];
x0=[-1.2;1];

x=x0;

i=1;
while 1
    
    % Calculation of the cost function.  Here, fun is the cost function, 
    % this is defined in a separate Matlab routine and is called here.  
    % The Hessian is known for this problem, that is why it is returned here.

    [f,g,Hessian] = fun(x);
    
    % Descent Direction:  The Hessian is known for this problem so I can use 
    % the full Newton method:
    
    p = -(Hessian^(-1))*g;
    % p=-g/norm(g);
    
    % Optimum Step length, initial guess for Step Length is 1:
    a = lsa(x,p,1);
    x = x+a*p;
    
    if(mod(i,10)==0)
        display(strcat('Cost Function:',num2str(f)))
        display(strcat('a=',num2str(a)))
    end
    
    if norm(g) < tol
        display(strcat('Convergence Reached: |\nabla f|=',num2str(norm(g))))
        i
        break;
    end
    
    if(i == maxit)
        disp('Maximum number of iteration reached');
        break;
    end
    
    i=i+1;
end

end