function [t, q, v]=RK_pendulo(tin, tfin, N, q0, v0, f)

t=linspace(tin,tfin,N); dt=t(2)-t(1);

q(1)=q0; v(1)=v0;
for i=1:N-1
   qc=q(i)+v(i)*dt/2;
   vc=v(i)+f(q(i))*dt/2;
   q(i+1)=q(i)+vc*dt;
   v(i+1)=v(i)+f(qc)*dt;
end

end