%abcdef
%222140
% x^2+(2+2)*y=2+2-7
% (1+0)*x-(2+2)*y^2=1-5*(0+2)
% mittelineaarne võrrandisüsteem
% joonis
ezplot('x^2+4*y+3=0');
hold on
yline(0)
xline(0)
ezplot('1*x-4*y^2+9=0');
hold on
grid on
% alglähenditeks võime võtta (-1.6,-1.4) ja (1.9,-1.7)
%1) lahendame hariliku iteratsioonimeetodiga
% avaldame võrrandisüsteemist x-i ja y-i
F=@(z) [z(1)^2+4*z(2)+3, z(1)-4*z(2)^2+9];
x=-1.6;
y=-1.4;
% x^2+4*y+3=0 -> x^2=-4*y-3 -> x=sqrt(-4*y-3) -> g11=0
% x^2+4*y+3=0 -> x^2=-4*y-3 -> x=sqrt(-4*y-3) -> g12=-2/(sqrt(-4*y-3))
% 1*x-4*y^2+10=0 -> 4y^2=x+10 -> y=sqrt(x+9)/4 -> g21=1/(8*sqrt(x+9))
% 1*x-4*y^2+10=0 -> 4y^2=x+10 -> y=sqrt(x+9)/4 -> g22= 0
gtul1=[0 -2/(sqrt(-4*y-3))
    1/(8*sqrt(x+9)) 0]
norm(gtul1,1)
%ei sobi>1
x2=1.9;
y2=-1.7;
gtul2=[0 -2/(sqrt(-4*y2-3))
    1/(8*sqrt(x+9)) 0]
norm(gtul2,1) %ei sobi >1
% x^2+4*y+3=0 -> 4*y=-x^2-3 -> y=(-x^2-3)/4 -> g11=(-1/2)*x
% x^2+4*y+3=0 -> 4*y=-x^2-3 -> y=(-x^2-3)/4 -> g12=0
% 1*x-4*y^2+10=0 -> x=4*y^2-10 -> x=4*y^2-9 -> g21=0
% 1*x-4*y^2+10=0 -> x=4*y^2-10 -> x=4*y^2-9 -> g22= 8*y
gtul3=[(-1/2)*x 0
    0 8*y]
norm(gtul3,1) %ei sobi>1
% x^2+4*y+3=0 -> x^2=-4*y-3 -> x=-sqrt(-4*y-3) -> g11=0
% x^2+4*y+3=0 -> x^2=-4*y-3 -> x=-sqrt(-4*y-3) -> g12=2/(sqrt(-4*y-3))
% 1*x-4*y^2+10=0 -> 4y^2=x+10 -> y=-sqrt(x+9)/4 -> g21=-1/(8*sqrt(x+9))
% 1*x-4*y^2+10=0 -> 4y^2=x+10 -> y=-sqrt(x+9)/4 -> g22= 0
gtul4=[0 2/(sqrt(-4*y-3))
    -1/(8*sqrt(x+10)) 0]
norm(gtul4,1)
%2) newtoni metod
F=@(z) [z(1)^2+4*z(2)+3;z(1)-4*z(2)^2+9]; %F on veeruvektor
% defineerime funktsiooni F tuletise
Ftuletis=@(z) [2*z(1),4;1,-8*y];
%alglähend (-1.6,-1.4)
z=[-1.6;-1.4]; % veeruvektor
sammud=0;
while (norm(F(z),1))>10^-6
z=z-inv(Ftuletis(z))*F(z);
sammud=sammud+1;
end
lahend1newton=z;
sammud1newton=sammud;
%alglähend (1.9,-1.7)
z=[1.9;-1.7]; % veeruvektor
sammud=0;
while (norm(F(z),1))>10^-6
z=z-inv(Ftuletis(z))*F(z);
sammud=sammud+1;
end
lahend2newton=z;
sammud2newton=sammud;
sammudnewton=[sammud1newton,sammud2newton]
lahendnewton=[lahend1newton, lahend2newton]
