% Integrate the general problem du/dt = Au forward in time
% using a 4-stage Runge-Kutta integration given:
%
% dt: timestep
% Tf: final time
% uinit: initial vector
%
% The numerical approximation is placed in the vector v
%

% Set initial condition into v
v(:,1) = uinit;
n = 1;
t(1) = 0;

% Integrate using 4-stage Runge-Kutta
while (t(n) < Tf),
  atmp     = dt*A*v(:,n);
  btmp     = dt*A*(v(:,n) + 0.5*atmp);
  ctmp     = dt*A*(v(:,n) + 0.5*btmp);
  dtmp     = dt*A*(v(:,n) +     ctmp);
  v(:,n+1) = v(:,n) + (1.0/6.0)*(atmp + 2*btmp + 2*ctmp + dtmp);
  t(n+1) = t(n) + dt;
  n = n + 1;
end



