function [t,x]=heun(f,x0,t0,tf,h)
   t=[t0:h:tf];
   x=zeros(length(x0),length(t));
   x(:,1)=x0;
   for k=1:length(t)-1
       k1=f(x(:,k),t(k));
       k2=f(x(:,k)+h*k1,t(k)+h);
       x(:,k+1)=x(:,k)+h*(k1/2+k2/2);
   end 
endfunction
