function [ t, y ] = stetter_midpoint ( n )

%*****************************************************************************80
%
%% stetter_midpoint() implements the midpoint method for stetter_ode().
%
%  Discussion:
%
%    We can't use a black-box midpoint method, because we want to
%    alternate between two step sizes.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 March 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the number of steps to take.
%
%  Output:
%
%    real T(N+1), Y(N+1): the times and estimated solutions.
%
  [ t0, y0, tstop ] = stetter_parameters ( );

  t = zeros ( n + 1, 1 );
  y = zeros ( n + 1, 1 );

  t(1) = t0;
  y(1) = y0;

  for i = 1 : n

    if ( mod ( i, 2 ) == 1 )
      dt = 0.5;
    else
      dt = 7.0;
    end

    tm = t(i) + 0.5 * dt;
    ym = y(i) / ( 1.0 - 0.5 * dt * stetter_lambda ( tm ) );

    t(i+1) = t(i) + dt;
    y(i+1) = 2.0 * ym - y(i);
 
  end

  return
end

