% One step integration of an ODE by RK2 method
% CCK 2009-02-12
function x1 = rk2(ode, x0, t0, h)
% f = function handle for ODE,  dx/dt = f(x,t)
% x0 = initial x
% t0 = initial time
% h = timestep (t1 - t0)
% result x1 is x(t1).

xhalf = x0 + (h/2) * ode(x0,t0);
dxdt = ode(xhalf, t0+h/2);
x1 = x0 + h * dxdt;