function [ t, y ] = stetter_trapezoidal ( n )

%*****************************************************************************80
%
%% stetter_trapezoidal() uses the trapezoidal method on the Stetter ODE.
%
%  Discussion:
%
%    We can't use a black-box trapezoidal 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
%
%                          yn = yo + 0.5 * dt * ( lambda(to)*yo + lambda(tn)*yn )
%  (1-0.5*dt*lambda(tn)) * yn = yo * (1+0.5*dt*lambda(to)
%                          yn = yo * (1+0.5*dt*lambda(to) / (1-0.5*dt*lambda(tn))
%
    t(i+1) = t(i) + dt;

    c = ( 1.0 + 0.5 * dt * stetter_lambda(t(i)) ) ...
      / ( 1.0 - 0.5 * dt * stetter_lambda(t(i+1)) );

    y(i+1) = y(i) * c;

  end

  return
end

