function y = rk2a( f, y0, t )
  % ----------------------------------------------------------------------
  % Jonathan R. Senning <jonathan.senning@gordon.edu>
  % Gordon College
  % March 22, 1999
  %
  % Usage: y = rk2a(@f, y0, t)
  %
  % Returns:
  %	one-dimensional array of y values associated with the t values
  %	passed into the function.
  %
  % Parameters:
  %	f:	handle of function equal to dy/dt.
  %	y0:	y value corresponding to t(1), initial t value
  %	t:	array of points to evaluate solution at
  %
  % This function implements a 2nd order Runge-Kutta algorithm to solve the
  % initial value problem
  %
  %	dy
  %	-- = f(y,t),     y(t_0) = y_0
  %	dt
  % 
  % This particular version is based on the algorithm presented in "Numerical
  % Analysis", 6th Edition, by Burden and Faires, Brooks-Cole, 1997.
  % ----------------------------------------------------------------------

  [m, n] = size( t );
  y = zeros( m, n );
  n = max( m, n );

  y(1) = y0;

  for i = 1 : n-1
    h = t(i+1) - t(i);
    k1 = h * f( y(i), t(i) ) / 2.0;
    y(i+1) = y(i) + h * f( y(i) + k1, t(i) + h / 2.0 );
  end

end
