clc;
disp('METODO DE NEWTON PARA SISTEMAS DE ECUACIONES NO LINEALES');
syms x y f g;
funcion_x= input('Introduce la primera Función: ');
funcion_g= input('Introduce la segunda Función: ');
x0= input('Introduce x0: ');
y0= input('introduce y0: ');
%funcion_x=x^2-10*x+y^2+8
%funcion_g=x*y^2+x-10*y+8
%x0=0; y0=0;
%DERIVADAS
der_funcion_fx=diff(funcion_x,x);
der_funcion_fy=diff(funcion_x,y);
der_funcion_gx=diff(funcion_g,x);
der_funcion_gy=diff(funcion_g,y);
X(1)=x0; Y(1)=y0;
N=2;
for i=1:N
%SUSTITUYENDO VALORES
%F
f1=subs(funcion_x,x,X(i));
f=subs(f1,y,Y(i));
%G
f2=subs(funcion_g,x,X(i));
g=subs(f2,y,Y(i));
%SUSTITUYENDO EN DERIVADAS
%FX
f3=subs(der_funcion_fx,x,X(i));
fx=subs(f3,y,Y(i));
%FY
f4=subs(der_funcion_fy,x,X(i));
fy=subs(f4,y,Y(i));
%GX
f5=subs(der_funcion_gx,x,X(i));
gx=subs(f5,y,Y(i));
%GY
f6=subs(der_funcion_gy,x,X(i));
gy=subs(f6,y,Y(i));
%DELTA X y DELTA Y
format long
delta_x=(-f*gy+g*fy)/(fx*gy-fy*gx);
delta_y=(-g*fx+f*gx)/(fx*gy-fy*gx);
delta_x=double(delta_x);
delta_y=double(delta_y);
disp('Delta x= ');
disp(delta_x);
disp('Delta y= ');
disp(delta_y);
X(i+1)=X(i)+delta_x;
Y(i+1)=Y(i)+delta_y;
disp('Nuevo Valor de x0');
disp(X(i+1));
disp('Nuevo Valor de y0');
disp(Y(i+1));
%CALCULANDO ERROR
error=sqrt((X(i+1)-X(i))^2+(Y(i+1)-Y(i))^2);
disp('Error= ');
disp(error);
end