function [xout,fout] = steepdesc_td(f,g,x0)
% steepest descent with Algor. 3.1 - backtrack
% f = f(x) is objective function
% x= n x 1 vector
% g = gradient(f)
itmax=100;
%n=length(g);
x=x0; % initial guess
a=1;  % a = alpha in Algor. 3.1
c=.0001;
for k=1:itmax
  k;  
  p=-g(x)  % search direction along -gradient of f
 a = 1; 
 f(x)
 while f(x+a*p) > f(x) + c*a*g(x)'*p  % backtrack
   a = .7*a;
 end  
  x = x+a*p
end  
xout = x;
fout = f(xout);