function Newton;

n=2;
eps=1.e-8;
max_err=eps+1;
max_iter=200;
iter=0;
x=zeros(1,2); x(1)=1.5; x(2)=1.5;

while (max_err>eps) && (iter<=max_iter)
    iter=iter+1;
    f=Find_functions(x);
    j=Find_Jacoby(x);
    h=Solut_System(j,f);
    max_err=0;
    for i=1:n
        if abs(h(i))>max_err
            max_err=abs(h(i));
        end
        x(i)=x(i)+h(i);
    end
    x
end
disp 'RESULT : '
max_err
iter
f=Find_functions(x);
x

function Jacoby=Find_Jacoby(x)
Jacoby(1,1)=2*x(1);
Jacoby(1,2)=3*x(2)*x(2);
Jacoby(2,1)=3*x(1)*x(1);
Jacoby(2,2)=2*x(2);

function f=Find_functions(x)
f(1)=-(x(1)^2+x(2)*(x(2)^2-1));
f(2)=-(x(1)*x(1)^2+x(2)^2-0.5);

function h=Solut_System(A,B);
d=A(1,1)*A(2,2)-A(1,2)*A(2,1);
d1=B(1)*A(2,2)-A(1,2)*B(2);
d2=A(1,1)*B(2)-B(1)*A(2,1);
h(1)=d1/d;
h(2)=d2/d;
