% Ylesanded 16, ylesanne 2
f=@(x,y) sin(x^2)/(y+3);
[x,y]=ode45(f,[1,4],3)
plot(x,y,'o')

% a) lahendame keskpunkti meetodiga
h=0.1;
x0=1;
xn=4;
n=(xn-x0)/h;
x(1)=1;
y(1)=3;

for i=2:(n+1) 
   x(i)=x(i-1)+h;
   y(i)=y(i-1)+h*f(x(i-1)+h/2,y(i-1)+h/2*f(x(i-1),y(i-1)));
end
x;
y;
ykeskp=y(n+1)
hold on
plot(x,y,'*')

% b) l'hendame keskpunkti meetodiga saadud (x,y) kuupsplainiga
y3splain=interp1(x,y,x,'spline')
hold on
plot(x,y3splain)

% c) interpolandi v22rtus, kui x=2.56
interp1(x,y,2.56,'spline')

