% Integrate the general problem du/dt = Au forward in time % using a 2nd order Adams-Bashforth 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 first step using Forward Euler v(:,n+1) = v(:,n) + dt*A*v(:,n); t(n+1) = t(n) + dt; n = n + 1; % Integrate remaining steps using AB2 while (t(n) < Tf), v(:,n+1) = v(:,n) + dt*A*(1.5*v(:,n) - 0.5*v(:,n-1)); t(n+1) = t(n) + dt; n = n + 1; end