function [x,xk]=SteepestDescent(f,fp,x0,tol,maxiter,tau,be,alinit)
% STEEPESTDESCENT steepest descent min. search with Armijo line search
%   [x,xk]=SteepestDescent(f,fp,x0,tol,maxiter,tau,be,alinit) finds an
%   approximate minimum of the function f with gradient fp, starting
%   at the initial guess x0. The remaining parameters are optional and
%   default values are used if they are omited. xk contains all the
%   iterates of the method.

if nargin<8, alinit=1; end;
if nargin<7, be=0.1; end;
if nargin<6, tau=0.5; end;
if nargin<5, maxiter=100; end;
if nargin<4, tol=1e-6; end;

x=x0;
xk=x0;
p=-feval(fp,x);
k=0;
while norm(p)>tol & k<maxiter
  al=alinit;
  while feval(f,x+al*p)>feval(f,x)-al*be*p'*p
    al=tau*al;
  end;
  x=x+al*p
  p=-feval(fp,x);
  k=k+1;
  xk(:,k+1)=x;
end;
