% Numerical Mathematics and Computing, Fifth Edition
% Ward Cheney & David Kincaid
% Brooks/Cole Publ. Co.
% (c) 2004
%
% file: newton_sys.m

% Newton's method for systems of three nonlinear equations 
% The same program with a different starting vector, 
% and it converges to another root!

x = [0.1; 1.2; 2.5]
for k=1:10
  f = [x(1)+x(2)+x(3)-3 ; 
     x(1)^2+x(2)^2+x(3)^2-5; 
     exp(x(1))+x(1)*x(2)-x(1)*x(3)-1]
  J = [1 1 1; 2*x(1) 2*x(2) 2*x(3) ; exp(x(1))+x(2)-x(3) x(1) -x(1)]
  h = J\f
  x = x-h
end

% Same system of functions, but different starting point and another solution! 

x = [1; 0; 1]
for k=1:10
  f = [x(1)+x(2)+x(3)-3 ; 
     x(1)^2+x(2)^2+x(3)^2-5; 
     exp(x(1))+x(1)*x(2)-x(1)*x(3)-1]
  J = [1 1 1; 2*x(1) 2*x(2) 2*x(3) ; exp(x(1))+x(2)-x(3) x(1) -x(1)]
  h = J\f
  x = x-h
end


