% H: SPD matrix (solving min_x x^T*H*x )
% x0: initial guess
% N: maximum number of iterations
%
% 

function [x, f] = modelsd(H, x0, N)

x=zeros(length(x0), N);
f=zeros(1,N);

% initial guess
x(:,1)=x0(:);
f(1)=0.5*x0'*H*x0;

for k=2:N
    d=-H*x(:,k-1);
    x(:,k)=x(:,k-1) + ( (d'*d)/(d'*H*d) ) * d;
    f(k)=0.5*x(:,k)'*H*x(:,k);    
end
