function [ th, w, t ] = RK2ndO_2ODE( t0, tN, N, th0, w0, g1, g2 )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

t=linspace(t0, tN, N);
dt=t(2)-t(1);

% initialise the RK loop
th(1)=th0;
w(1)=w0;

for i=2:N
    % the first guess of the central point is done by
    % first order Euler
    thc=th(i-1)+(dt/2)*g1(th(i-1), w(i-1), t(i-1));
    wc =w(i-1) +(dt/2)*g2(th(i-1), w(i-1), t(i-1));
    
    th(i)=th(i-1)+dt* g1(thc, wc, t(i-1)+dt/2);
    w(i) =w(i-1) +dt* g2(thc, wc, t(i-1)+dt/2);
end

end

