function [x,y] = odeRK4(F,Tint,y0,dt)
%ODERK4  Solve differential equations with a 2nd order explicit Runge Kutta method.
%   [TOUT,YOUT] = ODEEF(ODEFUN,TSPAN,Y0,DT) with TSPAN = [T0 TFINAL] integrates 
%   the system of differential equations y' = f(t,y) from time T0 to TFINAL 
%   with initial conditions Y0 and timestep DT. ODEFUN is a function handle. 
%   For a scalar T and a vector Y, ODEFUN(T,Y) must return a column vector 
%   corresponding to f(t,y). Each row in the solution array YOUT corresponds 
%   to a time returned in the column vector TOUT.  To obtain solutions at specific 
%   times T0,T1,...,TFINAL (all increasing or all decreasing), use TSPAN = 
%   [T0 T1 ... TFINAL]

x = [Tint(1):dt:Tint(2)]';
y = zeros(length(x),length(y0));
y(1,:) = y0;
for k = 1:length(x)-1
    y1 = y(k,:) + (dt/2)*F(x(k),y(k,:))';
    y2 = y(k,:) + (dt/2)*F(x(k)+dt/2,y1)';
    y3 = y(k,:) + dt*F(x(k)+dt/2,y2)';
    y(k+1,:) = y(k,:) + (dt/6)*(F(x(k),y(k,:))' + 2*F(x(k)+dt/2,y1)' + 2*F(x(k)+dt/2,y2)' + F(x(k+1),y3)');
end


