% Test of Newton's method in 2D
F=@(x) [x(1)^2-x(2)^4; x(1)-x(2)^3]; % function
DF=@(x) [2*x(1),-4*x(2)^3;1,-3*x(2)^2]; % Jacobian
x0=[0.7;0.7]; x_ast=[1;1];  % Initia guess and exact solution
abstol=1E-12; % absolut tolerance

res = [];
for reltol = 2.^(-(5:30)) 
  x = newtontc(x0,F,DF,reltol,abstol);
  res = [res; reltol, norm(x-x_ast)];
end

figure('name','Newton error'); set(gca,'fontsize',14);  
loglog(res(:,1),res(:,2),'r+');
xlabel('{\bf relative tolerance}');
ylabel('{\bf norm of error of approximate solution}');
title('{\bf variable relative tolerance, absolute tolerance = 10^{-12}}');
