%
% Script File h4P2.m - Solving A Nonlinear System of Equations 
%                      By Newton-Raphson method for Nrun iterations
% [X, Y, Z]=[2.1659, 1,4493, 1,4625];
n=3;
X=[1.0;  1.0;  1.0];                      % initial guess
format long                               % double precision
Nrun=10;                                  % number of iterations
for k=1:Nrun,
  F=[X(1)*X(2)-X(3)^2-1; ...
     X(1)*X(2)*X(3)-X(1)^2+X(2)^2-2; ...
     exp(X(1))-exp(X(2))-X(3)-3];
  A=[X(2),             X(1),             -2*X(3); ...
     X(2)*X(3)-2*X(1), X(1)*X(3)+2*X(2), X(1)*X(3); ...
     exp(X(1)),        exp(X(2)),        -1];
  s=0.002;  % Perturbation to avoid the near singularity
  dX=(A+s*eye(n))\F;      
  X=X-dX;
end
format short
[X'; F']    % Output solution and error (ideally F==0)