%NEWTONS METHOD FOR COMUTING ROOT OF SYSTEM 
%g_1(x,y,z) = x^2+y^2+z^2-3=0
%g_2(x,y,z) = x^2+y^2-z-1=0
%g_3(x,y,z) = x+y+z-3=0

clear all

x(1) = 1
x(2) = 0
x(3) = 1
x = x'

for k = 1:5
   
   M(1,1) = 2*x(1);
   M(1,2) = 2*x(2);
   M(1,3) = 2*x(3);
   M(2,1) = 2*x(1);
   M(2,2) = 2*x(2);
   M(2,3) = -1;
   M(3,1) = 1;
   M(3,2) = 1;
   M(3,3) = 1;
   
   g(1) = (x(1))^2+(x(2))^2+(x(3))^2-3;
   g(2) = (x(1))^2+(x(2))^2-x(3)-1;
   g(3) = x(1)+x(2)+x(3)-3;

   size(M)  
   size(g)
   x = x -inv(M)*g'

end