function [ xstar, success ] = simple_Gauss_Newton...
   ( x0, F, Fprime, eps, maxitr )
% [ xstar, success ] = simple_Gauss_Newton( x0, F, Fprime, eps, maxitr ) 
%   is analogous to newton_sys:  It computes up to maxitr iterations of
%   the Gauss--Newton method for the function F, with starting point x0 and
%   Jacobian matrix Fprime.  It stops when either the norm the step is less 
%   than eps or maxitr iterations have been exceeded.
%
% This is an illustrative function for Chapter 8 of Ackleh and Kearfott,
% "Applied Numerical Methods."

x = x0;
Fval = feval(F,x);
norm_step = realmax;
B = feval(Fprime,x);
success=0;
for k=1:maxitr
    k
    s = -pinv(B)*Fval;
    x = x+s;
    norm_step = norm(s,2)
    if (norm_step < eps) 
       success = 1;
       xstar = x;
       return
    end
    Fval = feval(F,x);
    B = feval(Fprime,x);
end
success = 0;
xstar = x;

end

