function [t,y] = RK2(f,tspan,y1,nstep)
 if(size(y1,2)>1) y1=y1'; end %Column vector
 t0= tspan(1); tn = tspan(2); 
 h = (tn-t0)/nstep;
 t = [t0:h:tn];
 nOfUnk = length(y1);
 y = [zeros(nstep,nOfUnk);y1'];
 yi = y1;
 for i=1:nstep
   ti = tn - (i-1)*h;
   k1 = f(ti,yi);
   k2 = f(ti-h,yi-h*k1);
   yi = yi - h*(k1+k2)/2;
   y(nstep-(i-1),:)=yi';
  end
