%% Simple minded Steepest Descent Demo
%% Fabian Waleffe MIT, May 5, 1995   for 18.330

%% define a symmetric positive definite matrix A and RHS b

  A=[1,-1;-1,10];  b=[1,2]';

% Initialize

  x=[0,0]'; bTb = b'*b;               k=0; hist=[k,x'];
  r= b-A*x; rTr = r'*r; 

%% Steepest descent algorithm

  while  rTr > (1.e-4*bTb) 

    Ar= A*r; 
    ak= rTr/(r'*Ar);
    x= x + ak*r;
    r= r - ak*Ar;
    rTr=r'*r;                 k= k+1;  hist=[hist;k,x'];
  end

%%

  plot(hist(:,2),hist(:,3)), axis image
  xlabel('x_1'), ylabel('x_2')

