function sol = NewtonSystemsalpha(F,JF,xzero,tolass,nmax) % solve a nonlinear system of equations F(x)=0, % with differentiable vector function F and % Jacobian matrix function JF c = 10*tolass*ones(size(xzero)); xnext = xzero; iter = 0; while (norm(c)> tolass || norm(F(xnext))>tolass && iter < nmax) xact = xnext; c = JF(xact)\(-F(xact)); Fdir = @(alpha) norm(F(xact + alpha * c)); alphamin = fminbnd(Fdir,-1,1); xnext = xact + alphamin*c; iter = iter + 1; end sol = xnext; end