%joonis
ezplot('x-0.25*cos(x-y)')
hold on
grid on
h=ezplot('y-0.25*sin(x+y)')
set(h,'Color','k')
title('Joonis')
legend('x=0.25*cos(x-y)','y=0.25*sin(x+y)')
%alglähendiks sobib x=0, y=0 (ligikaudne lõikepunkt jooniselt)
%HIM
%defineerime funktsioonid
g1=@(x,y)x-0.25*cos(x-y);
g2=@(x,y)y-0.25*sin(x+y);
x(1)=0; %x alglähend
y(1)=0; %y alglähend
i=1; %sammude arv
while max(abs(g1(x(i),y(i))),abs(g2(x(i),y(i))))>10^-3
    x(i+1)=0.25*cos(x(i)-y(i));
    y(i+1)=0.25*sin(x(i)+y(i));
    i=i+1;
end
x_vektor=x
y_vektor=y

%Newtoni meetod
f1=@(z)z(1)-0.25*cos(z(1)-z(2));
f2=@(z)z(2)-0.25*sin(z(1)+z(2));
F=@(z)[f1(z),f2(z)];
z=[0;0] %alglähend
i=0; %sammude arv
B(1,1)=1+0.25*sin(z(1)-z(2));
B(1,2)=-0.25*sin(z(1)-z(2));
B(2,1)=-0.25*cos(z(1)+z(2));
B(2,2)=1-0.25*cos(z(1)+z(2));
while norm(F(z),2)>10^-3
    z=z-inv(B)*F(z)';
    i=i+1;
end
z