clear
% Harjutustund nr. 17, ülesanne 3
x0=1;
xn=8;
n=100;
h=(xn-x0)/n;
f=@(x,y) -(y^2+x*y+x^2)/x^2;
x(1)=1;
y(1)=5;

% Euleri meetodiga
for (i=1:n)
    x(i+1)=x(i)+h;
    y(i+1)=y(i)+h*f(x(i),y(i));
end
yeuler=y(n+1)
plot(x,y,'b')
hold on

% prognoosi-korrelatsioonimeetod
for (i=1:n)
  y(i+1)=y(i)+h/2*f(x(i),y(i))+h/2*f(x(i+1),y(i)+h*f(x(i),y(i)));
end 
yprogn=y(n+1)
plot(x,y,'r')
hold off