function [ t, y ] = stetter_backward_euler ( n )

%*****************************************************************************80
%
%% stetter_backward_euler() uses the backward Euler method on the Stetter equation.
%
%  Discussion:
%
%    We can't use a black-box backward Euler 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

    t(i+1) = t(i) + dt;
%
%                        y(i+1) = y(i) + dt * lambda(t(i+1)) * y(i+1)
%  1-dt*lambda(t(i+1)) * y(i+1) = y(i)
%                        y(i+1) = y(i) / ( 1-dt*lambda(t(i+1)) )
%
    y(i+1) = y(i) / ( 1.0 - dt * stetter_lambda ( t(i+1) ) );

  end

  return
end

