% harjutustund nr. 7, ülesanne 3
% joonis
ezplot('20*x^2=1-2*x^3+4*y^3')
hold on
ezplot('2*x^3=3*y^2+10*y-5')
hold off
grid on
% alglähendid (-0.5,0.5),(0.5,0.5),(3.5,4.5)

% 1. lahendame Newtoni meetodiga
% vektorfunktsioon F
F=@(z) [1-2*z(1).^3+4*z(2).^3-20*z(1).^2;3*z(2).^2+10*z(2)-5-2*z(1).^3];
% F-i Jacobi maatriks
Ftuletis=@(z) [-6*z(1)^2-40*z(1),12*z(2)^2;-6*z(1)^2,6*z(2)+10];
% a) (-0.5,0.5)
z=[-0.5;0.5];
i=0;
while (norm(F(z),1))>10^-6
    z=z-inv(Ftuletis(z))*F(z);
    i=i+1;
end
lahend1newton=z
sammud1newton=i
% b) (0.5,0.5)
z=[0.5;0.5];
i=0;
while (norm(F(z),1))>10^-6
    z=z-inv(Ftuletis(z))*F(z);
    i=i+1;
end
lahend2newton=z
sammud2newton=i
% c) (3.5,4.5)
z=[3.5;4.5];
i=0;
while (norm(F(z),1))>10^-6
    z=z-inv(Ftuletis(z))*F(z);
    i=i+1;
end
lahend3newton=z
sammud3newton=i