function [x,k] = steep(g, x0, tol)
%
%  [x,k]=steep(g,x0,tol)
%  Find the minimum point of g by the steepest descent method. 
% 
%
x = x0;
kmax = 100;
for k = 1:kmax
    [gx,z] = feval(g,x);
    zn = norm(z,2);
    if (zn<tol) 
        break;
    end
    z = z/zn;
    alpha = fminsearch(@(alpha) h(alpha,x,z,g), 1);
    x = x-alpha*z;
end
if k==kmax 
    warning('The tolerance requirements has not been met.');
end


function y=h(alpha,x,z,g)
y = feval(g,x-alpha*z);

