%funkcija [t,Y] = RK2(fun,t0,Y0,tk,param,n)
%poisce resitev zacetnega problema 
%Y(t0)=Y0
%Y'=fun(t,y,param)
% na intervalu [t0,tk] z metodo Runge-Kutta reda 2.
% n je stevilo korakov
function [t,Y] = rk2(fun,t0,Y0,tk,param,n)
t=linspace(t0,tk,n+1);
h=t(2)-t(1);
Y=zeros(3,n+1);
Y(:,1)=Y0;
for i=1:n
	k1 = h*feval(fun,t(i),Y(:,i),param);
	k2 = h*feval(fun,t(i)+h,Y(:,i)+k1,param);
	Y(:,i+1) = Y(:,i)+(k1+k2)/2;
end
