function [x,xk]=Newton(f,fp,fpp,x0,tol,maxiter,tau,be,alinit)
% NEWTON Minimization with Newton descent and Armijo line search
%   [x,xk]=Newton(f,fp,fpp,x0,tol,maxiter,tau,be,alinit) finds an
%   approximate minimum of the function f with gradient fp and Hessian
%   fpp, 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<9, alinit=1; end;
if nargin<8, be=0.1; end;
if nargin<7, tau=0.5; end;
if nargin<6, maxiter=100; end;
if nargin<5, tol=1e-6; end;

x=x0;
xk=x0;
p=-feval(fpp,x)\feval(fp,x);
k=0;
while norm(feval(fp,x))>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(fpp,x)\feval(fp,x);
  k=k+1;
  xk(:,k+1)=x;
end;
