% Unit 5 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%=====================================================================
% modified Euler method for 2 coupled ordinary differential equations
%=====================================================================
function [x,v,t] = euler2(g, h, t0, x0, v0, tN, N)


% initialisation block
%----------------------
% step size
dt   = (tN-t0)/(N-1);

% arrays
t    = linspace(t0,tN,N);
x    = zeros(1,N);
v    = zeros(1,N);
%t(1) = t0; this is automatically initialized by linspace()
x(1) = x0;
v(1) = v0;

% integration block
%-------------------
for i=1:N-1

    x(i+1) = x(i) + g(x(i),v(i),t(i)) * dt;
    v(i+1) = v(i) + h(x(i),v(i),t(i)) * dt;

end

