syms x y z

% Define Nonlinear System.
F = [x + y^2 + z^2 - 9;
     z-y*sin(x);
     y+5*z];

% Define Variables Name.
v=[x,y,z];

% The Jacobian matrix:
J = jacobian(F,v);

% initial guess:
X = [-1; -2; 1];

% Constants.
maxiter = 10;
tol = 1e-12;

disp(' ')
disp('iteration    x(1)          x(2)           x(3)          norm(delta)')

for n=1:maxiter
   h = - subs(J,v,X) \ subs(F,v,X);
   X = X + h;
   disp(sprintf('%5i    %3.5e   %3.5e   %3.5e      %3.3e', ...
                 n,X(1),X(2),X(3),norm(h,inf)));

   if norm(h,inf) < tol
     break
     end
   end

if n==maxiter
   disp('*** Warning: may not have converged -- tolerance not satisfied')
   end
