clear
A = [ 1 4 2;0 7 10;8 2 23];
c = [3 -5 1]';
alpha=5;beta=8;gamma=0;
for i = 1:length(A(:, 1))
    for j = 1:length(A(i, :))
        A(i,j) = A(i, j) + power(-1, i-j+gamma) * beta;
    end
    c(i) = c(i) + power(-1, i-gamma)*alpha;
end
hold on
grid on
ezplot('-8 * power(x,2) - 15 * y = -2', [7, -7, 5, -15])
% y = (-8/15)*power(x,2) + 2/15; 
% x = sqrt((-15/8)*y + 1/4)
ezplot('16 * x + 6 * y = 0', [7, -7, 5, -15])
% x = (-6/16)*y; y = (-16/6)*x 
x = 0;
y = 0;
%Kasutades fsolve 
f=@(z)[-8 * power(z(1),2) - 15 * z(2) + 2, 16 * z(1) + 6 * z(2)];
l1 = fsolve(f, [x, y]) % l1 = -0.0495    0.1320 
%Kasutades HIM 
 g1 = @(z) (-8/15)*power(z(1),2) + 2/15; 
%sqrt((-15/8)*z(2) + 1/4); 
% (-15/16)*power((-15/8)*z(2) + 1/4,-1/2)
 g2 = @(z) (-6/16)*z(2); 
%(-16/6)*z(1); 
B(1, 1) = 0; %(-14/15)*x;
B(1, 2) = (-15/16)*power((-15/8)*y + 1/4,-1/2); %0;
B(2, 1) = (-16/6); %0;
B(2, 2) = 0; %(-6/16);%
t1 = norm(B, 1) % ei sobi 2.6667
B(1, 1) = (-16/15)*x;
B(1, 2) = 0;B(2, 1) = 0;
B(2, 2) = (-6/16);
t1 = norm(B, 1) % sobib 0.3750 
z=[x, y];
i=0;
while norm(f(z))>1e-6
    z(2)=g1(z);
    z(1)=g2(z);
    i=i+1;
end
z
i
%Kasutades Newton 
FT11 = @(z) -16 * z(1);
FT12 = @(z) -15;
FT21 = @(z) 16;
FT22 = @(z) 6;
z = [x, y]';
i=0;
while norm(f(z))>1e-6
    z = z - f(z).*([FT11(z), FT12(z); FT21(z), FT22(z)]^-1*f(z));
    i=i+1;
end
z
i