% Harjutustund 17, ylesanne 2
% t2pne lahendus
f=@(x,y) cos(x*y);
[x,y]=ode45(f,[2,10],2) % t2pne lahend 0.7936

% vajalikud suurused kirja
n=100;
x0=2;
xn=10;
h=(xn-x0)/n;

x(1)=2;
y(1)=2;
% a) lahendame Euleri meetodiga
for i=2:n+1
  x(i)=x(i-1)+h;
  y(i)=y(i-1)+h*f(x(i-1),y(i-1));
end
x
y
yeuler=y(n+1)

plot(x,y,'o-')
hold on
% b) prognoosi-korrelatsioonimeetodiga
for i=2:n+1
  x(i)=x(i-1)+h;
  y(i)=y(i-1)+h/2*f(x(i-1),y(i-1))+h/2*f(x(i),y(i-1)+h*f(x(i-1),y(i-1)));
end
x
y
yprognoos=y(n+1)
plot(x,y,'*-')
[yeuler yprognoos]