f=@(x,y) cos(x*y);
% lahendame täpselt
% [x,y]=ode45(f,[x_0,x_n],y_0)
[x,yline]=ode45(f,[2,10],2) % saime, et y_n=0.7936

n=100;  % osalõikude arv
x0=2;
xn=10;
h=(xn-x0)/n; % sammude arv
% algtingimus
x(1)=2;
y(1)=2;

% 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)
ytapne=0.7936;
x=[x0:h:xn];
plot(x,y,'o-')
% Lahendame prognoosi-korrelatsioonimeetodiga meetodiga
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
yprognoos=y(n+1)
hold on
plot(x,y,'*-')
% vordleme tulemusi [ytapne yeuler yprognoos]
[ytapne yeuler yprognoos] 