%
% File name: homotopynewton.m
% Author: Suh-Yuh Yang at NCU
% Date: September 21, 2018  
%
clear all;
format long 
x          = -2.961;
y          = 1.978;
M          = 100;
delta     = 10^(-10);
epsilon  = 10^(-10);
f1         = x^2 - 3*y^2 + 3;
f2         = x*y+6;
value    = sqrt((f1)^2 + (f2)^2); 
[0 x y value]
%
%
%
if value < epsilon  
    display('The approximate solution is obtained')
    [0 x y value] 
    break
end   
J = [2*x -6*y; y x];
for k=1:1:M
    XY = [x y]' - inv(J)*[f1 f2]';
    f1 = XY(1)^2 - 3*XY(2)^2 + 3;
    f2 = XY(1)*XY(2) + 6;
    value   = sqrt((f1)^2 + (f2)^2); 
    [k XY(1) XY(2) value] 
    if sqrt((XY(1) - x)^2 + (XY(2) - y)^2) < delta | value < epsilon
       display('The approximate solution is obtained')  
        [k XY(1) XY(2) value] 
        break 
    else
        x = XY(1);
        y = XY(2); 
        J = [2*x -6*y; y x]; 
    end
end
