%NMA_Newton
syms x y %POZOR, nutný balíček pro práci se symbolickými proměnnými!
%vstupy: f, g, X0
%  f = x^2 + 6*y^2 - 6;
%  g = x^2*y + 2*x^2 - 1;
f = x -y +2;
g = 4*sin(x)-y;
% f = log(x+1) -y;
% g = x^2 - x + y^2 - 8.75;

X0 = [-pi/2 , 4]; %jako ŘÁDEK

F=[f;g];

% Jacobiho matice
J = jacobian(F,[x,y]);
% matice soustavy 
A =  double(subs(J,{x,y},X0));
b = -double(subs(F,{x,y},X0));
DELTA0 = A\b;
X1 = X0' + DELTA0;

%tecne roviny pro f a g v bode X0 (tj. Taylorovy polynomy 1. stupne)
%-------------------------------------------------------------------
fprintf("Taylorovy polynomy\n")
fprintf("T^f_1(x,y) = (%4.4f) +(%4.4f)(x-%2.0f) + (%4.4f)(y-%2.0f)\n",-b(1),A(1,1),X0(1),A(1,2),X0(2))
fprintf("T^g_1(x,y) = (%4.4f) +(%4.4f)(x-%2.0f) + (%4.4f)(y-%2.0f)\n",-b(2),A(2,1),X0(1),A(2,2),X0(2))
% soustava rovnic
%----------------
fprintf("\nSoustava rovnic\n")
fprintf("(%4.4f) delta1 + (%4.4f) delta2 = (%4.4f)\n",A(1,1),A(1,2),b(1))
fprintf("(%4.4f) delta1 + (%4.4f) delta2 = (%4.4f)\n",A(2,1),A(2,2),b(2))
%------------
fprintf("\nX1 = %4.4f, %4.4f \n", X1(1), X1(2))

